Skip to content

Refactoring and new methods #273

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 11 commits into from
Feb 2, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ nosetests.xml
.idea
.project
.pydevproject
.vscode

# Web Drivers
chromedriver
Expand Down
12 changes: 10 additions & 2 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ self.scroll_to(selector, by=By.CSS_SELECTOR)

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

self.scroll_click(selector, by=By.CSS_SELECTOR) # DEPRECATED

self.click_xpath(xpath)

self.js_click(selector, by=By.CSS_SELECTOR)
Expand All @@ -166,6 +164,8 @@ self.ad_block()

self.get_domain_url(url)

self.get_beautiful_soup(source=None)

self.safe_execute_script(script)

self.download_file(file_url, destination_folder=None)
Expand All @@ -182,6 +182,14 @@ self.is_downloaded_file_present(file)

self.assert_downloaded_file(file)

self.assert_true(expr, msg=None)

self.assert_false(expr, msg=None)

self.assert_equal(first, second, msg=None)

self.assert_not_equal(first, second, msg=None)

self.assert_no_js_errors()

self.get_google_auth_password(totp_key=None)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ beautifulsoup4>=4.6.0
colorama==0.4.1
pyotp>=2.2.7
boto>=2.49.0
flake8==3.7.3
flake8==3.7.4
PyVirtualDisplay==0.2.1
-e .
107 changes: 38 additions & 69 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ def test_anything(self):
import time
import unittest
import uuid
from bs4 import BeautifulSoup
from seleniumbase import config as sb_config
from seleniumbase.common import decorators
from seleniumbase.config import settings
from seleniumbase.core.application_manager import ApplicationManager
from seleniumbase.core.testcase_manager import ExecutionQueryPayload
from seleniumbase.core.testcase_manager import TestcaseDataPayload
from seleniumbase.core.testcase_manager import TestcaseManager
from seleniumbase.core import download_helper
Expand Down Expand Up @@ -196,9 +193,7 @@ def is_link_text_present(self, link_text):
""" Returns True if the link text appears in the HTML of the page.
The element doesn't need to be visible,
such as elements hidden inside a dropdown selection. """
self.wait_for_ready_state_complete()
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
html_links = soup.find_all('a')
for html_link in html_links:
if html_link.text.strip() == link_text.strip():
Expand All @@ -209,9 +204,7 @@ def get_link_attribute(self, link_text, attribute, hard_fail=True):
""" Finds a link by link text and then returns the attribute's value.
If the link text or attribute cannot be found, an exception will
get raised if hard_fail is True (otherwise None is returned). """
self.wait_for_ready_state_complete()
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
html_links = soup.find_all('a')
for html_link in html_links:
if html_link.text.strip() == link_text.strip():
Expand Down Expand Up @@ -340,8 +333,7 @@ def click_partial_link_text(self, partial_link_text,
element = self.wait_for_partial_link_text(partial_link_text)
element.click()
return
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
html_links = soup.fetch('a')
for html_link in html_links:
if partial_link_text in html_link.text:
Expand Down Expand Up @@ -701,8 +693,7 @@ def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):
selector, by = self.__recalculate_selector(selector, by)
if self.is_element_present(selector, by=by):
return False
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
iframe_list = soup.select('iframe')
for iframe in iframe_list:
iframe_identifier = None
Expand All @@ -727,8 +718,7 @@ def switch_to_frame_of_element(self, selector, by=By.CSS_SELECTOR):
selector, by = self.__recalculate_selector(selector, by)
if self.is_element_present(selector, by=by):
return None
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
iframe_list = soup.select('iframe')
for iframe in iframe_list:
iframe_identifier = None
Expand Down Expand Up @@ -1438,12 +1428,15 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR,
selector, by=by, timeout=timeout)
self.__slow_scroll_to_element(element)

@decorators.deprecated("Use self.click() - It now scrolls before clicking")
def scroll_click(self, selector, by=By.CSS_SELECTOR):
# DEPRECATED - self.click() now scrolls to the element before clicking
# self.scroll_to(selector, by=by)
# self.scroll_to(selector, by=by) # Redundant
self.click(selector, by=by)

def click_xpath(self, xpath):
# Technically self.click() will automatically detect an xpath selector,
# so self.click_xpath() is just a longer name for the same action.
self.click(xpath, by=By.XPATH)

def js_click(self, selector, by=By.CSS_SELECTOR):
Expand Down Expand Up @@ -1552,13 +1545,24 @@ def ad_block(self):
except Exception:
pass # Don't fail test if ad_blocking fails

@decorators.deprecated("Use re.escape() instead! It does what you want!")
def jq_format(self, code):
# DEPRECATED - Use re.escape() instead, which does the action you want.
# DEPRECATED - re.escape() already does that thing you want!
return js_utils._jq_format(code)

def get_domain_url(self, url):
return page_utils.get_domain_url(url)

def get_beautiful_soup(self, source=None):
""" BeautifulSoup is a toolkit for dissecting an HTML document
and extracting what you need. It's great for screen-scraping! """
from bs4 import BeautifulSoup
if not source:
self.wait_for_ready_state_complete()
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
return soup

def safe_execute_script(self, script):
""" When executing a script that contains a jQuery command,
it's important that the jQuery library has been loaded first.
Expand Down Expand Up @@ -1611,6 +1615,18 @@ def assert_downloaded_file(self, file):
""" Asserts that the file exists in the Downloads Folder. """
assert os.path.exists(self.get_path_of_downloaded_file(file))

def assert_true(self, expr, msg=None):
self.assertTrue(expr, msg=None)

def assert_false(self, expr, msg=None):
self.assertFalse(expr, msg=None)

def assert_equal(self, first, second, msg=None):
self.assertEqual(first, second, msg=None)

def assert_not_equal(self, first, second, msg=None):
self.assertNotEqual(first, second, msg=None)

def assert_no_js_errors(self):
""" Asserts that there are no JavaScript "SEVERE"-level page errors.
Works ONLY for Chrome (non-headless) and Chrome-based browsers.
Expand Down Expand Up @@ -1885,39 +1901,6 @@ def select_option_by_value(self, dropdown_selector, option,
dropdown_by=dropdown_by, option_by="value",
timeout=timeout)

@decorators.deprecated("Use self.select_option_by_text() instead!")
def pick_select_option_by_text(self, dropdown_selector, option,
dropdown_by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
""" Selects an HTML <select> option by option text. """
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
self.__select_option(dropdown_selector, option,
dropdown_by=dropdown_by, option_by="text",
timeout=timeout)

@decorators.deprecated("Use self.select_option_by_index() instead!")
def pick_select_option_by_index(self, dropdown_selector, option,
dropdown_by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
""" Selects an HTML <select> option by option index. """
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
self.__select_option(dropdown_selector, option,
dropdown_by=dropdown_by, option_by="index",
timeout=timeout)

@decorators.deprecated("Use self.select_option_by_value() instead!")
def pick_select_option_by_value(self, dropdown_selector, option,
dropdown_by=By.CSS_SELECTOR,
timeout=settings.SMALL_TIMEOUT):
""" Selects an HTML <select> option by option value. """
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
timeout = self.__get_new_timeout(timeout)
self.__select_option(dropdown_selector, option,
dropdown_by=dropdown_by, option_by="value",
timeout=timeout)

############

def generate_referral(self, start_page, destination_page):
Expand Down Expand Up @@ -2495,12 +2478,6 @@ def delayed_assert_element(self, selector, by=By.CSS_SELECTOR,
self.__add_delayed_assert_failure()
return False

@decorators.deprecated("Use self.delayed_assert_element() instead!")
def check_assert_element(self, selector, by=By.CSS_SELECTOR,
timeout=settings.MINI_TIMEOUT):
""" DEPRECATED - Use self.delayed_assert_element() instead. """
return self.delayed_assert_element(selector, by=by, timeout=timeout)

def delayed_assert_text(self, text, selector="html", by=By.CSS_SELECTOR,
timeout=settings.MINI_TIMEOUT):
""" A non-terminating assertion for text from an element on a page.
Expand All @@ -2522,12 +2499,6 @@ def delayed_assert_text(self, text, selector="html", by=By.CSS_SELECTOR,
self.__add_delayed_assert_failure()
return False

@decorators.deprecated("Use self.delayed_assert_text() instead!")
def check_assert_text(self, text, selector="html", by=By.CSS_SELECTOR,
timeout=settings.MINI_TIMEOUT):
""" DEPRECATED - Use self.delayed_assert_text() instead. """
return self.delayed_assert_text(text, selector, by=by, timeout=timeout)

def process_delayed_asserts(self, print_only=False):
""" To be used with any test that uses delayed_asserts, which are
non-terminating verifications that only raise exceptions
Expand All @@ -2552,11 +2523,6 @@ def process_delayed_asserts(self, print_only=False):
else:
raise Exception(exception_output)

@decorators.deprecated("Use self.process_delayed_asserts() instead!")
def process_checks(self, print_only=False):
""" DEPRECATED - Use self.process_delayed_asserts() instead. """
self.process_delayed_asserts(print_only=print_only)

############

def __js_click(self, selector, by=By.CSS_SELECTOR):
Expand Down Expand Up @@ -2606,8 +2572,7 @@ def __get_href_from_link_text(self, link_text, hard_fail=True):

def __click_dropdown_link_text(self, link_text, link_css):
""" When a link may be hidden under a dropdown menu, use this. """
source = self.get_page_source()
soup = BeautifulSoup(source, "html.parser")
soup = self.get_beautiful_soup()
drop_down_list = soup.select('[class*=dropdown]')
for item in soup.select('[class*=HeaderMenu]'):
drop_down_list.append(item)
Expand Down Expand Up @@ -2769,6 +2734,10 @@ def setUp(self):
# Use Selenium Grid (Use --server=127.0.0.1 for localhost Grid)
self.use_grid = True
if self.with_db_reporting:
from seleniumbase.core.application_manager import (
ApplicationManager)
from seleniumbase.core.testcase_manager import (
ExecutionQueryPayload)
import getpass
self.execution_guid = str(uuid.uuid4())
self.testcase_guid = None
Expand Down
2 changes: 2 additions & 0 deletions seleniumbase/fixtures/js_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
import time
from selenium.common.exceptions import WebDriverException
from seleniumbase.common import decorators
from seleniumbase.config import settings
from seleniumbase.fixtures import constants

Expand Down Expand Up @@ -628,6 +629,7 @@ def slow_scroll_to_element(driver, element, browser):
time.sleep(0.162)


@decorators.deprecated("Use re.escape() instead, which does what you want!")
def _jq_format(code):
"""
DEPRECATED - Use re.escape() instead, which performs the intended action.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='seleniumbase',
version='1.19.0',
version='1.19.1',
description='Easy, Fast, Reliable Browser Automation & Testing Framework',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down Expand Up @@ -71,7 +71,7 @@
'colorama==0.4.1',
'pyotp>=2.2.7',
'boto>=2.49.0',
'flake8==3.7.3',
'flake8==3.7.4',
'PyVirtualDisplay==0.2.1',
],
packages=[
Expand Down