Update a raw selenium example
This commit is contained in:
parent
b25534ab4b
commit
b4595f8e7c
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
):
|
):
|
||||||
return WebDriverWait(self.driver, timeout).until(
|
try:
|
||||||
EC.visibility_of_element_located((by, selector))
|
return WebDriverWait(self.driver, timeout).until(
|
||||||
)
|
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
|
||||||
):
|
):
|
||||||
return WebDriverWait(self.driver, timeout).until(
|
try:
|
||||||
EC.element_to_be_clickable((by, selector))
|
return WebDriverWait(self.driver, timeout).until(
|
||||||
)
|
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
|
||||||
):
|
):
|
||||||
return WebDriverWait(self.driver, timeout).until(
|
try:
|
||||||
EC.invisibility_of_element((by, selector))
|
return WebDriverWait(self.driver, timeout).until(
|
||||||
)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue