selenium
play

Selenium Testing web applications Michal Ho ej ek, - PowerPoint PPT Presentation

Selenium Testing web applications Michal Ho ej ek, horejsekmichal@gmail.com def test_list_clients_contracts(api, client, contract): res = api.client.list_contracts(client.id) assert len(res) == 1 assert res[0] == contract www.seznam.cz


  1. Selenium Testing web applications Michal Ho ř ej š ek, horejsekmichal@gmail.com

  2. def test_list_clients_contracts(api, client, contract): res = api.client.list_contracts(client.id) assert len(res) == 1 assert res[0] == contract www.seznam.cz @horejsek

  3. def test_client_persons_suggest(test_app, client): data = { 'query': client.surname, } response = test_app.json('/client/search', data) assert response.status_code == 200 assert response[‘clients'][0] == client www.seznam.cz @horejsek

  4. describe 'Restaurant', () -> restaurant = new models.Restaurant name: 'Delicious dream' lastUpdate: '2013-01-01 18:30' describe '#getPrintalbeLastUpdate()', () -> it 'should return date as pretty string', () -> res = restaurant.getPrintalbeLastUpdate() assert.equal res, '1. ledna v 18:30' * Actually this is test of our web app with restaurant‘s lunch menus at Prague And ě l, lunchtimeandel.cz. Don‘t forget to use it when you will be around. :-) www.seznam.cz @horejsek

  5. Selenium „Selenium automates browsers. That's it!“ www.seznam.cz @horejsek

  6. from selenium import webdriver driver = webdriver.Chrome() driver.get('http://www.seznam.cz‘) print driver.title driver.quit() www.seznam.cz @horejsek

  7. from selenium.webdriver.common.keys import Keys input = driver.find_element_by_name('q') input.send_keys('selenium' + Keys.TAB) submit = driver.find_element_by_id(‘submit') submit.click() www.seznam.cz @horejsek

  8. driver.get_elm(‘f').fill_out_and_submit({ 'q': 'selenium', }) www.seznam.cz @horejsek

  9. >>> driver.go_to('http://www.seznam.cz‘) >>> driver.get_elm('resultCount‘) NoSuchElementException: Message: u'No element <* id=resultCount> found at http://www.seznam.cz/’ www.seznam.cz @horejsek

  10. f = driver.get_elm('link').download_file() f.method f.status_code f.headers f.data www.seznam.cz @horejsek

  11. elm = driver.get_elm('q') elm.send_keys('aa') # JavaScript changes DOM time.sleep(1) # Raises StaleElementException elm.send_keys('bb‘) www.seznam.cz @horejsek

  12. driver.get_elm('q').send_keys('aa') # JavaScript changes DOM time.sleep(1) # OK now driver.get_elm('q').send_keys('bb‘) www.seznam.cz @horejsek

  13. from selenium.webdriver.support.wait import WebDriverWait def callback(driver): return driver.find_element_by_id('id') wait = WebDriverWait(driver, timeout=10) wait.until(callback) www.seznam.cz @horejsek

  14. driver.wait_for_element(id_='id') www.seznam.cz @horejsek

  15. driver.contains_text('sherlock') driver.find_element_by_text('sherlock') www.seznam.cz @horejsek

  16. //div[contains(text(), "xxx")] //select[@name="country“]/option[@value="cr"] http://www.w3schools.com/xpath/xpath_intro.asp www.seznam.cz @horejsek

  17. class TestCase(WebdriverTestCase): domain = 'https://www.google.com' instances_of_driver = ONE_INSTANCE_PER_TESTCASE def _get_driver(self): return Chrome() def test_doodle(self): self.click('gbqfsb') res = self.contains_text('Doodles‘) self.assertTrue(res) www.seznam.cz @horejsek

  18. @expected_error_page(403) def test_no_permission_for_admin(self): self.go_to(‘/admin‘) @expected_error_messages('exists') def test_already_exists(self): self.get_elm('form').fill_out_and_submit({ 'item.username': 'admin', }) www.seznam.cz @horejsek

  19. <script type="text/javascript"> window.jsErrors = []; window.onerror = function(errorMessage) { window.jsErrors.push(errorMessage); } </script> www.seznam.cz @horejsek

  20. def test_doodle(driver): driver.click('gbqfsb') assert driver.contains_text('Doodles‘) def test_search(driver): driver.get_elm('gbqf').fill_out_and_submit({ 'q': 'hello', }) driver.wait_for_element(id_='resultStats') www.seznam.cz @horejsek

  21. Virtual X server Choices: Xvfb, Xephyr, Xvnc # apt-get install xvfb # pip install pyvirtualdisplay www.seznam.cz @horejsek

  22. from pyvirtualdisplay import Display display = Display(size=(800, 400)) display.start() # ... display.stop() www.seznam.cz @horejsek

  23. Selenium grid • More browsers • More operating systems • Faster tests www.seznam.cz @horejsek

  24. url = 'http://127.0.0.1:4444/wd/hub‘ desire = webdriver.DesiredCapabilities.FIREFOX.copy() driver = webdriver.Remote( command_executor=url, desired_capabilities=desire, ) www.seznam.cz @horejsek

  25. Check documentation for more info: http://horejsek.github.io/python-webdriverwrapper www.seznam.cz @horejsek

  26. Thank you! Michal Ho ř ej š ek, horejsekmichal@gmail.com www.seznam.cz @horejsek

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend