Top Banner
Winning the fight against test automation Chris Mills Mozilla
31

Winning the fight against test automation

Feb 23, 2017

Download

Technology

Chris Mills
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Winning the fight against test automation

Winning the fight against test automation

Chris Mills Mozilla

Page 2: Winning the fight against test automation

Who am I?

‣ Tech writer at Mozilla

‣ Writes about Web APIs on MDN

‣ Heads up the MDN Learning Area

‣ HTML.CSS.JS tinkerer

‣ Accessibility whinge bag

‣ Heavy metal drummer

Page 3: Winning the fight against test automation
Page 4: Winning the fight against test automation

In this talk

‣ The importance of cross browser testing

‣ What I wrote about it

‣ What I learned

‣ What was easy (and difficult)

Page 5: Winning the fight against test automation

Cross browser testing

Page 6: Winning the fight against test automation

(Important!)

‣ More than 1BN websites

‣ 3BN web users

‣ 8.1BN connected devices

‣ 24,000 mobile device types

‣ Lots of different browsers

‣ ~20% of users have a disability

Page 7: Winning the fight against test automation

Why don’t we?

‣ Less experience of X browser issues

‣ Many courses only teach Chrome

‣ Over-reliance on bleeding edge features

‣ And vendor-prefixed features

Page 8: Winning the fight against test automation

Other x-browser issues

‣ Browser vendors can be slow to fix bugs

‣ Some people still use browser sniffing rather than feature detection

Page 9: Winning the fight against test automation

And of course

‣ Toolchain/workflow perceived as difficult

Page 10: Winning the fight against test automation

So I wrote about it

Page 11: Winning the fight against test automation

We had to!

‣ Cross browser testing (MDN)

‣ Beginner-friendly guide to X browser

‣ Also friendly to front-end devs

Page 12: Winning the fight against test automation

Fitting it in

‣ What is X browser testing?

‣ Where + when should it happen?

‣ What should you test?

‣ How do you test it?

Page 13: Winning the fight against test automation

Solving common problems

‣ HTML

‣ CSS

‣ JavaScript

‣ Accessibility

Page 14: Winning the fight against test automation

Automating tests

‣ Task runners

‣ Selenium automation

‣ SauceLabs

‣ SauceLabs + Selenium

Page 15: Winning the fight against test automation

What was easy?

Page 16: Winning the fight against test automation

The webby stuff

‣ Of course!

‣ HTML/CSS/JavaScript is second nature

‣ We also know our accessibility

‣ And our browsers!

Page 17: Winning the fight against test automation

Writing the tests

‣ Selenium test logic is fairly easy (once you’ve got it working)

‣ Writing/running the tests was easy (I used Node); modules seem to have good docs

‣ SauceLabs integration was easy

Page 18: Winning the fight against test automation

Accessing WDvar webdriver = require('selenium-webdriver'),

By = webdriver.By,

until = webdriver.until;

var driver = new webdriver.Builder()

.forBrowser('firefox')

.build();

Page 19: Winning the fight against test automation

Accessing a pagedriver.get('http://www.google.com');

driver.findElement(By.name('q')).sendKeys('webdriver');

driver.findElement(By.name('btnG')).click();

Page 20: Winning the fight against test automation

Running a testdriver.sleep(2000).then(function() {

driver.getTitle().then(function(title) {

if(title === 'webdriver - Google Search') {

console.log('Test passed');

} else {

console.log('Test failed');

}

});

});

Page 21: Winning the fight against test automation

Finishing updriver.quit();

Page 22: Winning the fight against test automation

Accessing SauceLabsvar webdriver = require('selenium-webdriver'),

By = webdriver.By,

until = webdriver.until,

username = "YOUR-USER-NAME",

accessKey = "YOUR-ACCESS-KEY";

Page 23: Winning the fight against test automation

Accessing SauceLabsvar driver = new webdriver.Builder().

withCapabilities({

'browserName': 'chrome',

'platform': 'Windows XP',

'version': '43.0',

'username': username,

'accessKey': accessKey

}).

usingServer("https://" + username + ":" + accessKey +

"@ondemand.saucelabs.com:443/wd/hub").

build();

Page 24: Winning the fight against test automation

Updating SauceLabsvar saucelabs = new SauceLabs({

username : "YOUR-USER-NAME",

password : "YOUR-ACCESS-KEY"

});

Page 25: Winning the fight against test automation

Accessing SauceLabsdriver.getSession().then(function (sessionid){

driver.sessionID = sessionid.id_;

});

Page 26: Winning the fight against test automation

Accessing SauceLabs if(title === 'webdriver - Google Search') {

console.log('Test passed');

var testPassed = true;

} else {

console.log('Test failed');

var testPassed = false;

}

saucelabs.updateJob(driver.sessionID, {

name: 'Google search results page title test',

passed: testPassed

});

Page 27: Winning the fight against test automation

What was hard?

Page 28: Winning the fight against test automation

Setting up Selenium

‣ Working out what to use in the first place

‣ There’s lots of docs…

‣ …and they can be confusing

Page 29: Winning the fight against test automation

Setting up Selenium

‣ Do you use WebDriver, or Selenium Server, or Selenium RC, or Selenium Grid, or… ?

‣ Finding drivers for all the browsers you want to automate

‣ Installing the modules (or whatever) that you need for your server-side environment

‣ Making sure everything is communicating

Page 30: Winning the fight against test automation

We could benefit from

‣ Simple guides based on other server-side environments

‣ Better API docs for the SauceLabs API

Page 31: Winning the fight against test automation

Finito!

‣ Make the web work for everyone (Hacks)

‣ Cross browser testing (MDN)

‣ slideshare.net/chrisdavidmills

[email protected] @chrisdavidmills