Update a raw selenium example

This commit is contained in:
Michael Mintz 2022-09-22 23:18:29 -04:00
parent b25534ab4b
commit b4595f8e7c
2 changed files with 28 additions and 10 deletions

View File

@ -29,7 +29,7 @@ By this stage, newcomers to Selenium have evolved into legitimate test automatio
* [refined_raw.py](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium/refined_raw.py) * [refined_raw.py](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium/refined_raw.py)
By now, the test automation engineer has become an expert in breaking out code into reusable methods, and the test itself has been simplified down to a single page action per line. The code is easy to read and easy to maintain. The journey of writing a complete test automation framework for Selenium has begun. By now, the test automation engineer has become an expert in breaking out code into reusable methods, and the test itself has been simplified down to a single page action per line. The code is easy to read and easy to maintain. The error output is also simplified. The journey of writing a complete test automation framework for Selenium has begun.
* [simple_sbase.py](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium/simple_sbase.py) * [simple_sbase.py](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium/simple_sbase.py)

View File

@ -34,23 +34,41 @@ class RefinedRawSelenium(TestCase):
def wait_for_element_visible( def wait_for_element_visible(
self, selector, by="css selector", timeout=10 self, selector, by="css selector", timeout=10
): ):
try:
return WebDriverWait(self.driver, timeout).until( return WebDriverWait(self.driver, timeout).until(
EC.visibility_of_element_located((by, selector)) EC.visibility_of_element_located((by, selector))
) )
except Exception:
raise Exception(
"Element {%s} was not visible after %s seconds!"
% (selector, timeout)
)
def wait_for_element_clickable( def wait_for_element_clickable(
self, selector, by="css selector", timeout=10 self, selector, by="css selector", timeout=10
): ):
try:
return WebDriverWait(self.driver, timeout).until( return WebDriverWait(self.driver, timeout).until(
EC.element_to_be_clickable((by, selector)) EC.element_to_be_clickable((by, selector))
) )
except Exception:
raise Exception(
"Element {%s} was not visible/clickable after %s seconds!"
% (selector, timeout)
)
def wait_for_element_not_visible( def wait_for_element_not_visible(
self, selector, by="css selector", timeout=10 self, selector, by="css selector", timeout=10
): ):
try:
return WebDriverWait(self.driver, timeout).until( return WebDriverWait(self.driver, timeout).until(
EC.invisibility_of_element((by, selector)) EC.invisibility_of_element((by, selector))
) )
except Exception:
raise Exception(
"Element {%s} was still visible after %s seconds!"
% (selector, timeout)
)
def open(self, url): def open(self, url):
self.driver.get(url) self.driver.get(url)