SlideShare ist ein Scribd-Unternehmen logo
1 von 31
SCALATEST SELENIUM DSL
Scala days 2014 - Berlin
MATTHEW FARWELL
• Over 20 years development experience
• Project Lead on Scalastyle, style checker for Scala http://www.scalastyle.org
• Contributor to various open source projects, notably Scalatest, JUnit, Scala-
IDE
• Co-author with Josh Suereth of "sbt in Action" http://manning.com/suereth2/
• https://github.com/matthewfarwell/scaladays-2014-selenium
GOALS
• Present the Selenium DSL
• Show how it simplifies the writing of selenium tests.
• Show how it can be used to test a javascript heavy application
• Show how it can be integrated with other tests to make more useful
integration tests
• The future, well what I would like anyway
SELENIUM
• Selenium automates browsers.
• Firefox, Chrome, Internet Explorer, Safari, Opera, HtmlUnit
• Selenium has interfaces for Java, Python, Ruby, etc.
• We'll be looking at from the point of view of testing
• But we could use it for other stuff – automation of administration for example.
EXAMPLE (JAVA)
final WebDriver driver = new FirefoxDriver();
Wait<WebDriver> wait = new WebDriverWait(driver, 30);
driver.get("http://www.google.ch/");
driver.findElement(By.name("q")).sendKeys("Matthew Farwell");
driver.findElement(By.name("btnG")).click();
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
return webDriver.findElement(By.id("resultStats")) != null;
}});
boolean b = driver.findElement(By.tagName("body"))
.getText().contains("farwell.co.uk");
System.out.println((found ? "You are famous" : "Not famous enough, sorry"));
EXAMPLE (PYTHON)
driver = webdriver.Firefox()
driver.get("http://www.google.ch")
elem = driver.find_element_by_name("q")
elem.send_keys("Farwell")
elem.send_keys(Keys.RETURN)
assert "farwell.co.uk" in driver.find_by_element_id("body")
EXAMPLE (SCALA)
go to "http://www.google.ch/"
textField("q").value = "Farwell"
click on "btnG"
eventually {
val t = find(tagName("body")).get.text
}
t should include("farwell.co.uk")
println("Yay, you are famous")
- AmIFamousScala.scala
OUR APPLICATION
• https://github.com/matthewfarwell/scaladays-2014-selenium
$ sbt
> re-start
- Run tests from Eclipse
$ sbt
> re-start
> test
A REAL TEST
val baseUrl = "http://localhost:9100/"
"slash" should "redirect to admin index.html" in {
go to baseUrl
currentUrl should be (baseUrl + "admin/index.html#/users")
find("pageTitle").get.text should be("Users")
textField("userSearch").value should be('empty)
find("userUsername_2").get.text should be("matthew")
}
- UserSpec1.scala
ADDING EVENTUALLY
eventually {
find("userUsername_2").get.text should be("matthew")
}
- UserSpec2.scala
ADDING EVENTUALLY (2)
eventually {
find("pageTitle").get.text should be("Users")
textField("userSearch").value should be('empty)
find("userUsername_2").get.text should be("matthew")
}
- UserSpec2.scala
GETTING / SETTING VALUES
go to (baseUrl + "admin/index.html#/users")
eventually {
click on "userEdit_2"
}
eventually {
val tf = textField("userFullname")
tf.value should be("Matthew Farwell")
tf.isEnabled should be (true)
}
textField("userFullname").value = "Matthew Farwell is great"
- UserSpec3.scala
GETTING / SETTING VALUES
pwdField("password").value = "hello world"
pwdField("confirmPassword").value = "hello world"
find("error").get.text should be("Passwords do not match")
- UserSpec3.scala
DEBUGGING
capture to "foo.png"
println(currentUrl)
println(pageSource)
withScreenshot {
// some stuff
// if ModifiableMessage is thrown, screenshot is taken
}
DEBUGGING - REPORTERS
event match {
case e: TestFailed => {
val name = e.testName
web.captureTo(s"${name}.png")
println(web.pageSource)
}
}
- Common.scala
OTHER INPUT TYPES
• textField
• pwdField
• checkBox
• radioButton
• singleSel, multiSel
• HTML5 - emailField, colorField, dateField, dateTimeField, dateTimeLocalField,
monthField, numberField, rangeField, searchField, telField, timeField, urlField,
weekField
XPATH LOOKUPS
"list" should "default to 10 items" in {
go to (baseUrl + "admin/index.html#/users")
eventually {
val xp = "//tr//td[starts-with(@id, 'userUsername_')]"
val tds = findAll(xpath(xp)).map(_.text).toList
tds.size should be(10)
}
}
- UserSpec5.scala
PAGE OBJECT PATTERN
class HomePage extends Page {
val url = "localhost:9100/index.html"
}
val homePage = new HomePage
go to homePage
COOKIES
add cookie ("cookie_name", "cookie_value")
cookie("cookie_name").value should be ("cookie_value")
delete cookie "cookie_name"
ALERTS, FRAMES, WINDOWS
switch to alert
switch to frame(0) // switch by index
switch to frame("name") // switch by name
switch to window(windowHandle)
switch to activeElement
switch to defaultContent
NAVIGATION
goBack()
goForward()
reloadPage()
JAVASCRIPT
go to (host + "index.html")
val result1 = executeScript("return document.title;")
result1 should be ("Test Title")
val result2 = executeScript("return 'Hello ' + arguments[0]", "ScalaTest")
result2 should be ("Hello ScalaTest")
INTEGRATION TESTING
// create a new user
click on "newUser"
textField("username").value = "user"
// etc.
click on "submit"
// how do we test that the user has been created?
- UserSpec4.scala
INTEGRATION
• A lot of the time, we would like to assert something which isn't available
through the HTML front end
INTEGRATION TESTING
eventually {
val after = Services.listUsers().unmarshall
after.size should be(before.size + 1)
val u = after.find(_.username == "user").get
u.fullName should be(Some("Mr. User"))
u.id should not be (None)
}
- UserSpec4.scala
MULTI-BROWSER TESTING
abstract class UserSpecBase with Driver {
// tests here
}
class UserSpecChrome extends UserSpecBase with Chrome
class UserSpecFirefox extends UserSpecBase with Firefox
class UserSpecSafari extends UserSpecBase with Safari
- UserSpec6.scala
OUR CONTEXT
• Lots of legacy code, partially tested with selenium in Java / Python.
• Lots of new code, which has been tested with Scalatest selenium DSL
• A simple click on a web page can have effects way beyond CRUD
• Selenium used for testing pure HTML, GWT, Angular JS applications
OUR EXPERIENCE
• DSL is good for walking through a test – clearer and more readable than the
Java equivalent
• We have tests written by "developers" and "testers"
• Consistent tests – we use Scalatest for unit tests, UI tests and integration tests.
• Selenium DSL is integrated into Scalatest
• Always have ids on elements
• Our integration tests work with heterogeneous actions in the same test:
• we can perform an action in the Browser,
• then check call rest service,
• then check the database,
• call a command via ssh on a remote machine.
WHAT WE'D LIKE TO IMPROVE
IMPLICIT EVENTUALLY
eventually {
click on "userEdit_2"
}
eventually {
textField("foo").get.value should be ("bar")
}
eventually {
click on "btn"
}
eventually {
textField("baz").get.value should be ("flobble")
}
WHAT WE'D LIKE TO IMPROVE
SLOWING DOWN
eventually {
click on "userEdit_2"
}
eventually {
textField("foo").get.value should be ("bar")
}
eventually {
click on "userEdit_2"
}
eventually {
textField("foo").get.value should be ("bar")
}
ME AGAIN
• Matthew Farwell
• Twitter: @matthewfarwell
• Blog: http://randomallsorts.blogspot.ch/
• Scalastyle: http://www.scalastyle.org
• sbt in Action: http://manning.com/suereth2

Weitere ähnliche Inhalte

Was ist angesagt?

Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java DevelopersYakov Fain
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit TestChiew Carol
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with JestMichał Pierzchała
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
Apache Ant
Apache AntApache Ant
Apache AntAli Bahu
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With XtendSven Efftinge
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaChristopher Bartling
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr TolstykhCodeFest
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Morris Singer
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma Christopher Bartling
 
Php unit for drupal 8
Php unit for drupal 8Php unit for drupal 8
Php unit for drupal 8valuebound
 

Was ist angesagt? (19)

Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr Tolstykh
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven TomacJavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
 
Php unit for drupal 8
Php unit for drupal 8Php unit for drupal 8
Php unit for drupal 8
 

Ähnlich wie Scaladays 2014 introduction to scalatest selenium dsl

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scalascalaconfjp
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrationstakezoe
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesAlfresco Software
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaAgile Testing Alliance
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile InfrastructuresAntons Kranga
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform ResearchVasil Remeniuk
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform researchVasil Remeniuk
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitMike Pfaff
 

Ähnlich wie Scaladays 2014 introduction to scalatest selenium dsl (20)

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Aurelia intro
Aurelia introAurelia intro
Aurelia intro
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrations
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 

Kürzlich hochgeladen

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 

Kürzlich hochgeladen (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 

Scaladays 2014 introduction to scalatest selenium dsl

  • 1. SCALATEST SELENIUM DSL Scala days 2014 - Berlin
  • 2. MATTHEW FARWELL • Over 20 years development experience • Project Lead on Scalastyle, style checker for Scala http://www.scalastyle.org • Contributor to various open source projects, notably Scalatest, JUnit, Scala- IDE • Co-author with Josh Suereth of "sbt in Action" http://manning.com/suereth2/ • https://github.com/matthewfarwell/scaladays-2014-selenium
  • 3. GOALS • Present the Selenium DSL • Show how it simplifies the writing of selenium tests. • Show how it can be used to test a javascript heavy application • Show how it can be integrated with other tests to make more useful integration tests • The future, well what I would like anyway
  • 4. SELENIUM • Selenium automates browsers. • Firefox, Chrome, Internet Explorer, Safari, Opera, HtmlUnit • Selenium has interfaces for Java, Python, Ruby, etc. • We'll be looking at from the point of view of testing • But we could use it for other stuff – automation of administration for example.
  • 5. EXAMPLE (JAVA) final WebDriver driver = new FirefoxDriver(); Wait<WebDriver> wait = new WebDriverWait(driver, 30); driver.get("http://www.google.ch/"); driver.findElement(By.name("q")).sendKeys("Matthew Farwell"); driver.findElement(By.name("btnG")).click(); wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver webDriver) { return webDriver.findElement(By.id("resultStats")) != null; }}); boolean b = driver.findElement(By.tagName("body")) .getText().contains("farwell.co.uk"); System.out.println((found ? "You are famous" : "Not famous enough, sorry"));
  • 6. EXAMPLE (PYTHON) driver = webdriver.Firefox() driver.get("http://www.google.ch") elem = driver.find_element_by_name("q") elem.send_keys("Farwell") elem.send_keys(Keys.RETURN) assert "farwell.co.uk" in driver.find_by_element_id("body")
  • 7. EXAMPLE (SCALA) go to "http://www.google.ch/" textField("q").value = "Farwell" click on "btnG" eventually { val t = find(tagName("body")).get.text } t should include("farwell.co.uk") println("Yay, you are famous") - AmIFamousScala.scala
  • 8. OUR APPLICATION • https://github.com/matthewfarwell/scaladays-2014-selenium $ sbt > re-start - Run tests from Eclipse $ sbt > re-start > test
  • 9. A REAL TEST val baseUrl = "http://localhost:9100/" "slash" should "redirect to admin index.html" in { go to baseUrl currentUrl should be (baseUrl + "admin/index.html#/users") find("pageTitle").get.text should be("Users") textField("userSearch").value should be('empty) find("userUsername_2").get.text should be("matthew") } - UserSpec1.scala
  • 10. ADDING EVENTUALLY eventually { find("userUsername_2").get.text should be("matthew") } - UserSpec2.scala
  • 11. ADDING EVENTUALLY (2) eventually { find("pageTitle").get.text should be("Users") textField("userSearch").value should be('empty) find("userUsername_2").get.text should be("matthew") } - UserSpec2.scala
  • 12. GETTING / SETTING VALUES go to (baseUrl + "admin/index.html#/users") eventually { click on "userEdit_2" } eventually { val tf = textField("userFullname") tf.value should be("Matthew Farwell") tf.isEnabled should be (true) } textField("userFullname").value = "Matthew Farwell is great" - UserSpec3.scala
  • 13. GETTING / SETTING VALUES pwdField("password").value = "hello world" pwdField("confirmPassword").value = "hello world" find("error").get.text should be("Passwords do not match") - UserSpec3.scala
  • 14. DEBUGGING capture to "foo.png" println(currentUrl) println(pageSource) withScreenshot { // some stuff // if ModifiableMessage is thrown, screenshot is taken }
  • 15. DEBUGGING - REPORTERS event match { case e: TestFailed => { val name = e.testName web.captureTo(s"${name}.png") println(web.pageSource) } } - Common.scala
  • 16. OTHER INPUT TYPES • textField • pwdField • checkBox • radioButton • singleSel, multiSel • HTML5 - emailField, colorField, dateField, dateTimeField, dateTimeLocalField, monthField, numberField, rangeField, searchField, telField, timeField, urlField, weekField
  • 17. XPATH LOOKUPS "list" should "default to 10 items" in { go to (baseUrl + "admin/index.html#/users") eventually { val xp = "//tr//td[starts-with(@id, 'userUsername_')]" val tds = findAll(xpath(xp)).map(_.text).toList tds.size should be(10) } } - UserSpec5.scala
  • 18. PAGE OBJECT PATTERN class HomePage extends Page { val url = "localhost:9100/index.html" } val homePage = new HomePage go to homePage
  • 19. COOKIES add cookie ("cookie_name", "cookie_value") cookie("cookie_name").value should be ("cookie_value") delete cookie "cookie_name"
  • 20. ALERTS, FRAMES, WINDOWS switch to alert switch to frame(0) // switch by index switch to frame("name") // switch by name switch to window(windowHandle) switch to activeElement switch to defaultContent
  • 22. JAVASCRIPT go to (host + "index.html") val result1 = executeScript("return document.title;") result1 should be ("Test Title") val result2 = executeScript("return 'Hello ' + arguments[0]", "ScalaTest") result2 should be ("Hello ScalaTest")
  • 23. INTEGRATION TESTING // create a new user click on "newUser" textField("username").value = "user" // etc. click on "submit" // how do we test that the user has been created? - UserSpec4.scala
  • 24. INTEGRATION • A lot of the time, we would like to assert something which isn't available through the HTML front end
  • 25. INTEGRATION TESTING eventually { val after = Services.listUsers().unmarshall after.size should be(before.size + 1) val u = after.find(_.username == "user").get u.fullName should be(Some("Mr. User")) u.id should not be (None) } - UserSpec4.scala
  • 26. MULTI-BROWSER TESTING abstract class UserSpecBase with Driver { // tests here } class UserSpecChrome extends UserSpecBase with Chrome class UserSpecFirefox extends UserSpecBase with Firefox class UserSpecSafari extends UserSpecBase with Safari - UserSpec6.scala
  • 27. OUR CONTEXT • Lots of legacy code, partially tested with selenium in Java / Python. • Lots of new code, which has been tested with Scalatest selenium DSL • A simple click on a web page can have effects way beyond CRUD • Selenium used for testing pure HTML, GWT, Angular JS applications
  • 28. OUR EXPERIENCE • DSL is good for walking through a test – clearer and more readable than the Java equivalent • We have tests written by "developers" and "testers" • Consistent tests – we use Scalatest for unit tests, UI tests and integration tests. • Selenium DSL is integrated into Scalatest • Always have ids on elements • Our integration tests work with heterogeneous actions in the same test: • we can perform an action in the Browser, • then check call rest service, • then check the database, • call a command via ssh on a remote machine.
  • 29. WHAT WE'D LIKE TO IMPROVE IMPLICIT EVENTUALLY eventually { click on "userEdit_2" } eventually { textField("foo").get.value should be ("bar") } eventually { click on "btn" } eventually { textField("baz").get.value should be ("flobble") }
  • 30. WHAT WE'D LIKE TO IMPROVE SLOWING DOWN eventually { click on "userEdit_2" } eventually { textField("foo").get.value should be ("bar") } eventually { click on "userEdit_2" } eventually { textField("foo").get.value should be ("bar") }
  • 31. ME AGAIN • Matthew Farwell • Twitter: @matthewfarwell • Blog: http://randomallsorts.blogspot.ch/ • Scalastyle: http://www.scalastyle.org • sbt in Action: http://manning.com/suereth2

Hinweis der Redaktion

  1. No loop – just an example
  2. Find returns an Option