Skip to content

Adding new features and improving on older ones. #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
![](https://cdn2.hubspot.net/hubfs/100006/images/SB_Logo8s.png "SeleniumBase")

**WebDriver automation simplified by extending Python's unittest framework.**

[![](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase) [![Join the chat at https://gitter.im/seleniumbase/SeleniumBase](https://badges.gitter.im/seleniumbase/SeleniumBase.svg)](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

**The Future of Web Automation & Testing**
SeleniumBase simplifies web automation & testing with WebDriver in the same way that jQuery, AnglularJS, and ReactJS simplify web development with JavaScript. All tests using SeleniumBase's BaseCase class inherit Python's unittest.TestCase class, which allows for running tests automatically with Pytest and Nosetest. This framework can use the Page Object Model for test structure, as well as all features of WebDriver and Python's unittest.

![](https://cdn2.hubspot.net/hubfs/100006/images/sb_demo.gif "SeleniumBase")

Expand Down
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
theme: jekyll-theme-cayman
title: SeleniumBase
description: The Future of Web Automation & Testing
description: WebDriver automation simplified by extending Python's unittest framework.
43 changes: 43 additions & 0 deletions examples/boilerplates/base_test_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'''
You can use this as a boilerplate for your test framework.
Define your customized library methods in a master class like this.
Then have all your test classes inherit it.
BaseTestCase will inherit SeleniumBase methods from BaseCase.
'''

from seleniumbase import BaseCase


class BaseTestCase(BaseCase):

def setUp(self):
super(BaseTestCase, self).setUp()
# Add custom setUp code for your tests AFTER the super().setUp()

def tearDown(self):
# Add custom tearDown code for your tests BEFORE the super().tearDown()
super(BaseTestCase, self).tearDown()

def login_to_site(self):
# <<< Placeholder for actual code. Add your code here. >>>
# Add frequently used methods like this in your base test case class.
# This reduces the amount of duplicated code in your tests.
# If the UI changes, the fix only needs to be applied in one place.
pass

def example_method(self):
# <<< Placeholder for actual code. Add your code here. >>>
pass


'''
# Now you can do something like this in your test files:

from base_test_case import BaseTestCase

class MyTests(BaseTestCase):

def test_example(self):
self.login_to_site()
self.example_method()
'''
10 changes: 10 additions & 0 deletions examples/boilerplates/boilerplate_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .base_test_case import BaseTestCase
from .page_objects import HomePage


class MyTestClass(BaseTestCase):

def test_boilerplate(self):
self.login_to_site()
self.example_method()
self.assert_element(HomePage.html)
37 changes: 0 additions & 37 deletions examples/boilerplates/master_test_case.py

This file was deleted.

9 changes: 5 additions & 4 deletions examples/boilerplates/page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class HomePage(object):
html = "html"
ok_button = "#ok"
cancel_button = "#cancel"
see_items_button = "button.items"
Expand All @@ -26,13 +27,13 @@ class CheckoutPage(object):
'''
# Now you can do something like this in your test files:

from master_class import MasterTestCase
from page_objects import HomePage, ShoppingPage, CheckoutPage
from .base_test_case import BaseTestCase
from .page_objects import HomePage, ShoppingPage, CheckoutPage

class MyTests(MasterTestCase):
class MyTests(BaseTestCase):

def test_example(self):
self.open(RANDOM_SHOPPING_WEBSITE)
self.login_to_site()
self.click(HomePage.see_items_button)
self.click(ShoppingPage.buyable_item)
self.click(ShoppingPage.add_to_cart)
Expand Down
2 changes: 1 addition & 1 deletion examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''

from seleniumbase import BaseCase
from google_objects import HomePage, ResultsPage
from .google_objects import HomePage, ResultsPage


class GoogleTests(BaseCase):
Expand Down
30 changes: 29 additions & 1 deletion help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ self.double_click(selector, by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
self.click_chain(selectors_list, by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT, spacing=0)

self.is_link_text_present(link_text)

self.get_href_from_link_text(link_text)

self.wait_for_href_from_link_text(link_text, timeout=settings.SMALL_TIMEOUT)

self.click_link_text(link_text, timeout=settings.SMALL_TIMEOUT)

self.click_link(link_text, timeout=settings.SMALL_TIMEOUT)

self.click_partial_link_text(partial_link_text, timeout=settings.SMALL_TIMEOUT)

self.get_text(selector, by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
Expand Down Expand Up @@ -61,6 +69,10 @@ self.is_text_visible(text, selector, by=By.CSS_SELECTOR)

self.find_visible_elements(selector, by=By.CSS_SELECTOR)

self.is_element_in_frame(selector, by=By.CSS_SELECTOR)

self.enter_frame_of_element(selector, by=By.CSS_SELECTOR)

self.execute_script(script)

self.set_window_size(width, height)
Expand All @@ -69,6 +81,8 @@ self.maximize_window()

self.activate_jquery()

self.bring_to_front(selector, by=By.CSS_SELECTOR)

self.highlight(selector, by=By.CSS_SELECTOR, loops=4, scroll=True)

self.scroll_to(selector, by=By.CSS_SELECTOR)
Expand All @@ -81,10 +95,24 @@ self.click_xpath(xpath)

self.jquery_click(selector, by=By.CSS_SELECTOR)

self.hide_element(selector, by=By.CSS_SELECTOR)

self.hide_elements(selector, by=By.CSS_SELECTOR)

self.show_element(selector, by=By.CSS_SELECTOR)

self.show_elements(selector, by=By.CSS_SELECTOR)

self.remove_element(selector, by=By.CSS_SELECTOR)

self.remove_elements(selector, by=By.CSS_SELECTOR)

self.jq_format(code)

self.get_domain_url(url)

self.safe_execute_script(script)

self.download_file(file_url, destination_folder=None)

self.save_file_as(file_url, new_file_name, destination_folder=None)
Expand All @@ -110,7 +138,7 @@ self.jquery_update_text_value(selector, new_value, by=By.CSS_SELECTOR,
self.jquery_update_text(selector, new_value, by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT)

self.hover_on_element(selector)
self.hover_on_element(selector, by=By.CSS_SELECTOR)

self.hover_and_click(hover_selector, click_selector,
hover_by=By.CSS_SELECTOR, click_by=By.CSS_SELECTOR,
Expand Down
6 changes: 3 additions & 3 deletions integrations/selenium_ide/convert_ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def main():
if '(u"' in line:
uni = "u"
has_unicode = True
command = '''%sself.click_link_text(%s"%s")''' % (
command = '''%sself.click(%s"link=%s")''' % (
whitespace, uni, link_text)
seleniumbase_lines.append(command)
continue
Expand Down Expand Up @@ -468,7 +468,7 @@ def main():
# quote_type = data.group(1)
link_text = data.group(2)
if int(line_num) < num_lines - 2:
regex_string = (r'''^\s*self.click_link_text\(["|']'''
regex_string = (r'''^\s*self.click\(["|']link='''
+ re.escape(link_text) + r'''["|']\)\s*$''')
data2 = re.match(regex_string, lines[line_num+1])
if data2:
Expand All @@ -489,7 +489,7 @@ def main():
out_file = codecs.open(converted_file_name, "w+")
out_file.writelines(seleniumbase_code)
out_file.close()
print("%s successfully created from %s\n" % (
print('>>> "%s" successfully created from %s\n' % (
converted_file_name, webdriver_python_file))


Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
# Let console output be seen. Don't override the pytest plugin.
addopts = --capture=no --ignore conftest.py
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pip>=9.0.1
setuptools>=38.5.1
ipython==5.4.1
selenium==3.8.0
selenium==3.8.1
nose==1.3.7
pytest==3.4.0
pytest-html==1.16.1
Expand Down
17 changes: 12 additions & 5 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
Expand Down Expand Up @@ -112,10 +113,13 @@ def get_remote_driver(browser_name, headless, servername, port):
desired_capabilities=(
webdriver.DesiredCapabilities.SAFARI))
if browser_name == constants.Browser.PHANTOM_JS:
return webdriver.Remote(
command_executor=address,
desired_capabilities=(
webdriver.DesiredCapabilities.PHANTOMJS))
with warnings.catch_warnings():
# Ignore "PhantomJS has been deprecated" UserWarning
warnings.simplefilter("ignore", category=UserWarning)
return webdriver.Remote(
command_executor=address,
desired_capabilities=(
webdriver.DesiredCapabilities.PHANTOMJS))


def get_local_driver(browser_name, headless):
Expand Down Expand Up @@ -158,7 +162,10 @@ def get_local_driver(browser_name, headless):
if browser_name == constants.Browser.SAFARI:
return webdriver.Safari()
if browser_name == constants.Browser.PHANTOM_JS:
return webdriver.PhantomJS()
with warnings.catch_warnings():
# Ignore "PhantomJS has been deprecated" UserWarning
warnings.simplefilter("ignore", category=UserWarning)
return webdriver.PhantomJS()
if browser_name == constants.Browser.GOOGLE_CHROME:
try:
chrome_options = webdriver.ChromeOptions()
Expand Down
Loading