Slide 1

Slide 1 text

Automatisierte Browser-Tests mit (gocept.)Selenium Wolfgang Schnerring gmbh & co. kg PyCon DE 2011, Leipzig Wolfgang Schnerring Selenium 07.10.2011 1 / 19

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Einführung Web 2.0 und JavaScript Wolfgang Schnerring Selenium 07.10.2011 3 / 19

Slide 4

Slide 4 text

Einführung Browser-Fernsteuerung Wolfgang Schnerring Selenium 07.10.2011 4 / 19

Slide 5

Slide 5 text

Selenium Architektur nach: http://seleniumhq.org/projects/remote-control/ Wolfgang Schnerring Selenium 07.10.2011 5 / 19

Slide 6

Slide 6 text

Selenium Funktionsumfang Wolfgang Schnerring Selenium 07.10.2011 6 / 19

Slide 7

Slide 7 text

Selenium API open http://www.google.de/ type name=q zope waitForVisible id=suggestions assertText //div[@id=’suggestions’])/ul/li[2] *fisch Wolfgang Schnerring Selenium 07.10.2011 7 / 19

Slide 8

Slide 8 text

Selenium API open http://www.google.de/ type name=q zope waitForVisible id=suggestions assertText //div[@id=’suggestions’])/ul/li[2] *fisch s = selenium.selenium(server, port, ’∗firefox’) s.start() s.open(’http://www.google.de/’) s.type(’name=q’, ’zope’) # won’t work because of asynchronity! assertTrue(s.is_visible(’id=suggestions’))) assertEqual(s.get_text(’//div[@id="suggestions"])/ul/li[2]’, ’fisch’) Wolfgang Schnerring Selenium 07.10.2011 7 / 19

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

gocept.selenium Beispielcode class AutocompleteTest(gocept.selenium.wsgi.TestCase): def test_search_field_should_show_suggestions(self): s = self.selenium s.open(’http://www.google.de/’) s.type(’name=q’, ’zope’) s.waitForVisible(’id=suggestions’)) s.assertText(’//div[@id="suggestions"])/ul/li[2]’, ’∗fisch’) Wolfgang Schnerring Selenium 07.10.2011 9 / 19

Slide 11

Slide 11 text

gocept.selenium Befehlstypen Aktionen click(locator), type(), dragAndDrop() Abfragen getText(locator), getSelectedValues(), getHeight() Assertions assertText(locator, pattern), assertElementPresent() Asynchron waitForElementPresent(), waitForXpathCount() Wolfgang Schnerring Selenium 07.10.2011 10 / 19

Slide 12

Slide 12 text

gocept.selenium Locators Element-ID getText(’id=navigation’) CSS getText(’css=div.navigation li a’) XPath getText(’//div[@id="suggestions"])/ul/li[2]’) Javascript getText(’document.forms[’myForm’].myDropdown’) Wolfgang Schnerring Selenium 07.10.2011 11 / 19

Slide 13

Slide 13 text

Abstraktion click(’id=menu1’) waitForElementPresent(’css=div.lightbox’) waitForVisible(’css=div.lightbox’) click(’css=a.close’) waitForElementNotPresent(’css=div.lightbox’) Wolfgang Schnerring Selenium 07.10.2011 12 / 19

Slide 14

Slide 14 text

Abstraktion click(’id=menu1’) waitForElementPresent(’css=div.lightbox’) waitForVisible(’css=div.lightbox’) click(’css=a.close’) waitForElementNotPresent(’css=div.lightbox’) click(’id=menu1’) assertLightboxOpens() click(’css=a.close’) assertLightboxCloses() Wolfgang Schnerring Selenium 07.10.2011 12 / 19

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Test-Integration Setup Wolfgang Schnerring Selenium 07.10.2011 14 / 19

Slide 17

Slide 17 text

Test-Integration Layer class Layer(object): __bases__ = (OTHER_LAYER,) def setUp(self): # [start browser] def tearDown(self): # [kill browser] def testSetUp(self): def testTearDown(self): Wolfgang Schnerring Selenium 07.10.2011 15 / 19

Slide 18

Slide 18 text

Test-Integration einfacher mit zope.testrunner from my.package.main import my_wsgi_callable class AutocompleteTest(gocept.selenium.wsgi.TestCase): layer = gocept.selenium.wsgi.Layer(my_wsgi_callable) def test_search_field_should_show_suggestions(self): s = self.selenium s.open(’http://%s:%s/foo’ % (self.layer.host, self.layer.port) s.assertTextPresent(’Hello, world!’) Wolfgang Schnerring Selenium 07.10.2011 16 / 19

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Ausblick & Ressourcen Selenium-2.x (WebDriver-API) JsTestDriver http://seleniumhq.org http://release.seleniumhq.org/selenium-core/1.0/reference.html http://pypi.python.org/pypi/gocept.selenium Wolfgang Schnerring Selenium 07.10.2011 18 / 19

Slide 21

Slide 21 text

Wir suchen Mitarbeiter in Halle! Softwareentwicklung Web Python TDD Systemadministration Gentoo/KVM Puppet Nagios Bei Interesse: mich ansprechen oder jobs@gocept.com Wolfgang Schnerring Selenium 07.10.2011 19 / 19