25
Web test automation & Best practices by

Gediminas Guoba - Test automation & best practices

Embed Size (px)

DESCRIPTION

Testing by hand is easy but takes a lot of time. At Drivr (drivr.com) we try to automate everything including testing before releasing our applications. I will share our experience how we have reached zero manual testing after releases and how we are sure that our applications still work, CSS changes haven't broken layout, and our web sites still look good on different browsers and on mobile devices.

Citation preview

Page 1: Gediminas Guoba - Test automation & best practices

Web test automation

& Best practices

by

Page 3: Gediminas Guoba - Test automation & best practices

About drivr.com

Page 4: Gediminas Guoba - Test automation & best practices

Selenium 2.0 (WebDriver)

Page 5: Gediminas Guoba - Test automation & best practices

IWebDriver driver = new FirefoxDriver();

driver.Navigate().GoToUrl("http://www.google.com/");// Find the text input element by its name

IWebElement query = driver.FindElement(By.Name("q"));// Enter something to search for

query.SendKeys("Cheese");// Now submit the form. WebDriver will find the form for us from the

element

query.Submit();// Google's search is rendered dynamically with JavaScript.// Wait for the page to

load, timeout after 10 seconds

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });// Should see: "Cheese -

Google Search"

System.Console.WriteLine("Page title is: " + driver.Title);//Close the browser

driver.Quit();

Sample code

Page 6: Gediminas Guoba - Test automation & best practices

Challenges

Page 7: Gediminas Guoba - Test automation & best practices

Challenge 1: Layout, CSS, form

changes brakes tests

<form>

<input type=”text” id=”q” />

<input type=”submit” value=”Search” id=”submitBtn” />

</form>

Don’t use weak selectors like:

findElement by //form/input[type=submit]

Use id’s instead:

findElement by id ‘submitBtn’

Page 8: Gediminas Guoba - Test automation & best practices

Challenge 1: Layout, CSS, form

changes brakes tests

<form>

<input type=”text” id=”q” />

<input type=”submit” class=”btn” id=”submitBtn” />

</form>

Don’t use CSS class selectors like:

findElement by .btn

Use id’s instead:

findElement by id ‘submitBtn’

Page 9: Gediminas Guoba - Test automation & best practices

Challenge 1: Layout, CSS, form

changes brakes tests

Page 11: Gediminas Guoba - Test automation & best practices

Challenge 3: Data changes in

database

Don’t rely on data which can change

Have a “save” corner for your data

Or create a test data automatically

Or… have a separate test environment

Page 12: Gediminas Guoba - Test automation & best practices

Challenge 4: Simulation of different

situations

Special data config on DB

Data stubs in API

Data mocking on client side (later)

Page 13: Gediminas Guoba - Test automation & best practices

Challenge 5: Test stability

“Thread.Sleep()” is your enemy

Use WebDriverWait instead // Google's search is rendered dynamically with JavaScript.// Wait for the page to load, timeout after 10

seconds

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });

Retry, retry, wait and retry again

Do it simple!

Page 14: Gediminas Guoba - Test automation & best practices

Challenge 6: Long running tests

Run tests in parallel

Split big test to a few smaller tests

Replace with JavaScript unit tests where

possible (later)

1000 unit tests takes 2-3 seconds

4-5 UI tests takes one minute

Page 15: Gediminas Guoba - Test automation & best practices

Challenge 7: Run tests in Production

Choose some tests to confirm your release to

production

We do not change any data

Page 16: Gediminas Guoba - Test automation & best practices

Challenge 0: Automation oriented

culture

Every team member must agree on automated

tests

Test is as much important as feature is

Don’t leave tests for “next sprint”

Do not release if even single test fails

Be prepared for long learning

Page 17: Gediminas Guoba - Test automation & best practices

Testing on different

browsers

Page 18: Gediminas Guoba - Test automation & best practices

Cross platform testing

Selenium supports many browsers + iOS and

Android

Run different OS for Selenium?

Sauce Labs

http://saucelabs.com

BrowserStack

http://www.browserstack.com/

Page 19: Gediminas Guoba - Test automation & best practices

Screenshot comparison

Page 21: Gediminas Guoba - Test automation & best practices

Javascript tests

Page 22: Gediminas Guoba - Test automation & best practices

JavaScript unit tests

Jasmine testing framework

http://pivotal.github.io/jasmine/

AngularJS + HTTP mocking

http://docs.angularjs.org/api/ngMock.$httpBackend

Karma as tests runner

http://karma-runner.github.io/

E2E testing with

AngularJShttp://docs.angularjs.org/guide/dev_guide.e2e-testing

Thousands of tests in a seconds

Much stable than UI tests

Much easier to write!

Page 23: Gediminas Guoba - Test automation & best practices

Final word

Test automation is continuous process

Be prepared for long learning

Screenshot comparison rules!

AngularJS and Javascript unit testing is

awesome!

Page 25: Gediminas Guoba - Test automation & best practices

Thank You!

Questions?