Download - Selenium
![Page 1: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/1.jpg)
AUTOMATED UI TESTING
Presented by Chung Chieh-Lun
![Page 2: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/2.jpg)
Integration Test
“Without automated end to end tests delivering a new release of an
application becomes burdensome !”
![Page 3: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/3.jpg)
Integration Test
![Page 4: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/4.jpg)
Integration Test
Only UI exposed
The investment pays off quickly
Automated tests
![Page 5: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/5.jpg)
Selenium
“Selenium automates browser”
![Page 6: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/6.jpg)
Selenium
Free
Whatever users do in the browser
Get everything at: http://www.seleniumhq.org/
![Page 7: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/7.jpg)
Can Selenium automate app?
![Page 8: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/8.jpg)
Selenium Language Bindings Core
Third Party
Java C# Ruby Python Javascript
![Page 9: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/9.jpg)
How to use Java JRE/JDK Install latest Selenium Serverhttps://selenium-release.storage.googleapis.com/index.html
Install Java Selenium Client Driverex. ChromeDriverhttp://chromedriver.storage.googleapis.com/index.html
![Page 10: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/10.jpg)
Selenium Components
Selenium IDE
Selenium RC (Remote Control)
Selenium Grid
Selenium 2.0 (Webdriver)
![Page 11: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/11.jpg)
Selenium IDE
Firefox add-on Exports as a reusable script to play back
![Page 12: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/12.jpg)
![Page 13: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/13.jpg)
Selenium RC
Launch RC Server
Write Your Commands
Send to RC Server
Interact with the browser
Respond to RC Server
Fetch new instructions
Repeat
middleman
Your Selenium Commands
![Page 14: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/14.jpg)
Selenium RC
Step 1 -> RC Server relay instructions from your test program
Step 2 -> Selenium Core will execute the instructions as javascript commands
Step 3 -> The browser will obey the instructions of Selenium Core and relay its response to the RC Server
Step 4 -> The RC Server will receive the response of the browser and then display the results to you
Step 5 -> RC Server will fetch the next instruction from your test script to repeat the whole cycle
![Page 15: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/15.jpg)
Webdriver[Selenium 2.0]
Controls the browser from the OS level
![Page 16: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/16.jpg)
Redundancy Confusion
Webdriver Selenium RC
Speed
API
BroserSupport
Need a real, visible browserHtmlUnit browser
Simple
![Page 17: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/17.jpg)
Headless HtmlUnit Browser
GUI-Less browser for Java programs
A way to simulate a browser for testing
http://htmlunit.sourceforge.net/gettingStarted.html
![Page 18: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/18.jpg)
If you want to...
Run your tests on different browser and operating system
Third-Party
OR?
![Page 19: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/19.jpg)
Selenium Grid
Distribute test execution across several machines
Save time in execution of your test suites
http://www.guru99.com/introduction-to-selenium-grid.html
![Page 20: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/20.jpg)
WebDriverJS
Asynchronous
Example : Google search [Java]
driver.get("http://www.google.com");driver.findElement(By.name("q")).sendKeys("webdriver");driver.findElement(By.name("btnG")).click();assertEquals("webdriver - Google Search", driver.getTitle());
![Page 21: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/21.jpg)
WebDriverJS
Promise An object that can execute whatever you give it after it has finished
driver.get("http://www.google.com") .then(function() { return driver.findElement(By.name("q")); }) .then(function(q) { return q.sendKeys("webdriver"); }) .then(function() { return driver.findElement(By.name("btnG")); }) .then(function(btnG) { return btnG.click(); }) .then(function() { return driver.getTitle(); }) .then(function(title) { assertEquals("webdriver - Google Search", title); });
![Page 22: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/22.jpg)
ControlFlow
A wrapper for Promise
It maintains a list of schedule actions
The exposed functions in WebDriverJS do not actually do their stuff
It puts every new entry in the then callback of the last entry of the list
![Page 23: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/23.jpg)
ControlFlow
![Page 24: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/24.jpg)
NodeJS NPM
Selenium RC npm install soda https://github.com/learnboost/soda
![Page 25: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/25.jpg)
NodeJS NPM
WebDriverJS for Node npm install selenium-webdriver npm install webdriverio npm install protractor
![Page 26: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/26.jpg)
More...
https://github.com/beatfactor/nightwatchnpm
![Page 27: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/27.jpg)
Protractor
API: https://angular.github.io/protractor/#/api
$ webdriver-manager update
$ webdriver-manager start
$ protractor spec.js
![Page 28: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/28.jpg)
Demo
Test Items Redirect /login
Show the signin panel
Autheticate a user
![Page 29: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/29.jpg)
Workflow Integration
Can we just run
a single command
and
everything go smooth ?
![Page 30: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/30.jpg)
Gulp
“Automate and enhance your workflow”
![Page 31: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/31.jpg)
Gulp
Javascript Test Framework
Install and start a standalone selenium server
Synchronised browser testing
![Page 32: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/32.jpg)
Gulp – BrowserSync
npm install browserSync
http://www.browsersync.io/
![Page 33: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/33.jpg)
npm install selenium-standalone
Install and start selenium server
![Page 34: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/34.jpg)
Gulp
![Page 35: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/35.jpg)
Gulp Test
![Page 36: Selenium](https://reader030.vdocuments.us/reader030/viewer/2022032506/55cb7d0abb61ebc14f8b48af/html5/thumbnails/36.jpg)
Demo
Test Items Link button
Set cookie value
Take a screenshot