Automatic Functional Testing with Selenium and SauceLabs

25
FUNCTIONAL TESTING automatically with Selenium @josephj6802

Transcript of Automatic Functional Testing with Selenium and SauceLabs

Page 1: Automatic Functional Testing with Selenium and SauceLabs

FUNCTIONAL TESTINGautomatically with Selenium

@josephj6802

Page 3: Automatic Functional Testing with Selenium and SauceLabs

Functional Testing in Stackla

Can u borrow me your iPhone 5?

Page 4: Automatic Functional Testing with Selenium and SauceLabs

Headless vs. SeleniumHeadless Browser

Selenium

Page 5: Automatic Functional Testing with Selenium and SauceLabs

MisunderstandingsOnly available in Firefox

Need to write Java for Selenium test cases or use Selenium IDE to record

(Probably true in Selenium 1.0)

Page 6: Automatic Functional Testing with Selenium and SauceLabs

Selenium 2.0Selenium 1.0 + = Selenium 2.0

npm install selenium-webdriver

gem install selenium-webdriver

composer.phar require facebook/webdriver

Page 7: Automatic Functional Testing with Selenium and SauceLabs

Manipulate Chrome w/ Node.js + ChromeDriver

Get Feet Wet!

var webdriver = require(‘selenium-webdriver'), expect = require('expect'), driver = new webdriver.Builder().forBrowser('chrome').build();

driver.get('http://stackla.com');driver.getTitle().then(function (title) { expect(title).toBe(“Stackla - Social Media Aggregator“);});driver.quit();

Tip: Node.JS 4.x

Page 8: Automatic Functional Testing with Selenium and SauceLabs

Scalability

Page 9: Automatic Functional Testing with Selenium and SauceLabs

Scalability

Page 10: Automatic Functional Testing with Selenium and SauceLabs

Trial Run with

Page 11: Automatic Functional Testing with Selenium and SauceLabs

Manual Testing

Page 12: Automatic Functional Testing with Selenium and SauceLabs

Manual Testing

Page 14: Automatic Functional Testing with Selenium and SauceLabs

My ToolsBrowser testing on SauceLabs

Jasmine

Webdriver.io

Grunt

SauceLabs

Page 15: Automatic Functional Testing with Selenium and SauceLabs

exports.config = { user: process.env.SAUCE_USERNAME, key: process.env.SAUCE_ACCESS_KEY, updateJob: true, specs: ['./tests/*_test.js'], capabilities: [{ browserName: 'firefox', version: 37, name: 'Firefox Selenium tests', build: 'build-' + process.env.TRAVIS_BUILD_ID, 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER },{ browserName: 'chrome', version: 43, name: 'Chrome Selenium tests', build: 'build-' + process.env.TRAVIS_BUILD_ID, 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER },{ browserName: 'internet explorer', version: 11, name: 'IE Selenium tests', build: 'build-' + process.env.TRAVIS_BUILD_ID, 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER },{ browserName: 'safari', version: 6, name: 'Safari Selenium tests', build: 'build-' + process.env.TRAVIS_BUILD_ID, 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER }], baseUrl: 'http://localhost:8585', framework: 'jasmine', reporter: ‘spec'};

./wdio-saucelab.conf.js // browser - webdriver instancedescribe('Index Page', function() { it('should have title', function* () { yield browser.url('/index.html'); expect(yield browser.getTitle()).toBe('Browser Testing'); }); it('shoud have Stackla widget', function* () { yield browser.url('/'); expect(yield browser.isExisting('.stackla-widget')); });});

./tests/index_test.js

<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>Browser Testing</title> </head> <body> <h1>Browser Testing</h1> <div class="stackla-widget" data-id="6605" data-hash="5663ac9e3843f" data-ct="" data-alias="josephj.stackla.com" data-ttl="30" style="width: 100%; overflow: hidden;"></div> <script type="text/javascript"> (function (d, id) { if (d.getElementById(id)) return; var t = d.createElement('script'); t.type = 'text/javascript'; t.src = '//assetscdn.stackla.com/media/js/widget/fluid-embed.js'; t.id = id; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(t); }(document, 'stackla-widget-js')); </script> </body></html>

http://localhost:8585/index.html

Need to build a web server and tunnel

$ wdio wdio-saucelab.conf.js

Page 16: Automatic Functional Testing with Selenium and SauceLabs

Automated Build

Page 17: Automatic Functional Testing with Selenium and SauceLabs

TravisCI

My ToolsDelegating testing task to CI Server

Jasmine

Webdriver.io

Grunt

SauceLabs

Page 18: Automatic Functional Testing with Selenium and SauceLabs

Enable Build

https://github.com/josephj/browser-testing

Page 19: Automatic Functional Testing with Selenium and SauceLabs

Whenever user makes git push

Set environment variables for SauceConnect

Settings

Page 20: Automatic Functional Testing with Selenium and SauceLabs

language: node_jsnode_js: - "4.1"before_script: - npm install grunt-cli -g - npm install webdriverio -g - npm install jasmine -gaddons: sauce_connect: truebranches: only: - master - gh-pagesscript: - grunt test:saucelabs

Config File./travis.yml

Page 21: Automatic Functional Testing with Selenium and SauceLabs

https://travis-ci.org/josephj/browser-testing

Let’s Build!

$ git push

Page 22: Automatic Functional Testing with Selenium and SauceLabs

Todo List

Page 23: Automatic Functional Testing with Selenium and SauceLabs

Pricing

Unlimted Automation Testing but slow with 1 parallel VM

Better speed but with limited time

Fastest and quiet enough time

Page 24: Automatic Functional Testing with Selenium and SauceLabs

Google Trends

BrowserStack is the most popular one