Skip to content

Commit

Permalink
Merge pull request #25 from StatCan/feature-24-add-clear-command
Browse files Browse the repository at this point in the history
Feature added. Clear command and clear command unit test added.
  • Loading branch information
DominicParent authored Mar 9, 2023
2 parents e48bc1b + 413dca6 commit bec1d7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tass/actions/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def type(driver, find=_find_element, text='', **kwargs):
find(driver, **kwargs).send_keys(text)


def clear(driver, find=_find_element, **kwargs):
try:
find(driver, **kwargs).clear()
except WebDriverException as e:
print("Exception: ", e, " trying again")
find(driver, **kwargs).clear()


def load_url(driver, url=''):
driver.get(url)

Expand Down
21 changes: 21 additions & 0 deletions tests/actions/test_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ def test_SeleniumType(self):
.get_attribute('value'), text)
driver.quit()

def test_SeleniumClear(self):
url = os.path.join(pathlib.Path().resolve(), self.test_page_url)
for browser in self.drivers:
with self.subTest(browser=browser.browser):
driver = browser(self.config)
driver.get('file://' + url)
text = 'Selenium Test Type'
driver.find_element('id', 'nameField').send_keys(text)
self.assertEqual(
driver
.find_element('id', 'nameField')
.get_attribute('value'), text)
selenium.clear(
driver,
locator={"by": "id", "value": "nameField"})
self.assertEqual(
driver
.find_element('id', 'nameField')
.get_attribute('value'), '')
driver.quit()

def test_SeleniumReadAttribute(self):
url = os.path.join(pathlib.Path().resolve(), self.test_page_url)
for browser in self.drivers:
Expand Down

0 comments on commit bec1d7f

Please sign in to comment.