web testing with selenium

43
XBOSoft, Inc. All Rights Reserved. 1 Web Testing with Selenium

Upload: xbosoft

Post on 15-Jul-2015

238 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Web testing with Selenium

XBOSoft, Inc. All Rights Reserved. 1

Web

Testing

with

Selenium

Page 2: Web testing with Selenium

XBOSoft

Founded in 2006Dedicated to software quality

Software QA Consulting

Software Testing

Offices in San Francisco, Beijing and Amsterdam

XBOSoft, Inc. All Rights Reserved. 2

Page 3: Web testing with Selenium

House RulesEveryone except the speakers are muted

Questions via the gotowebinar control on the right side of your screen or

through Twitter @XBOSoft

Questions can be asked throughout the webinar - we’ll try to answer them

at the end.

You will receive info on recording after the webinar

XBOSoft, Inc. All Rights Reserved. 3

Page 4: Web testing with Selenium

Meet Our Speakers

• VP Sales & Marketing at XBOSoft

• 15 years Marketing and Sales in High Tech

• Love the outdoors, reading and parenthood

XBOSoft, Inc. All Rights Reserved. 4

Steve Gohre

• Sr. Software Developer in Test at Eid Passport

• Over 20 years of test automation experience

• Veteran speaker

• Quality Week 1999

• PNSQC 2007

• PNSQC 2011

• PNSQC 2013

• Better Software West 2015 (June)

• Enjoys golf and fine wine

Alan Ark

Sabrina Gasson

• Marketing Manager of XBOSoft

• Emails you all regularly to join our

industry hot topic webinars

• And invites you all to download our latest

trends in software testing whitepapers.

Page 5: Web testing with Selenium

Who is Alan Ark?

Sr. Software Developer in Test at Eid Passport in Hillsboro, Oregon, USA

Over 20 years of automated testing experienceOver 8 years with WatirAbout a year with Selenium

Page 6: Web testing with Selenium

Agenda

Intro on SeleniumTips and TricksPitfalls to avoid

Ask questions as we go!

Page 7: Web testing with Selenium

Watir?

Web Application Testing in Ruby

A different open source project that drives browsers for test automation

Page 8: Web testing with Selenium

What is Selenium?

A tool to automate browsers!

Quick regression testing across many browsers

Automate web based admin tasks

Page 9: Web testing with Selenium

Why Selenium over Watir?

Choice

More widely supported

More bindings available

Page 10: Web testing with Selenium

Regression testing!

Repetitive test efforts

Reproducible tests across many browsers

Time consuming

Page 11: Web testing with Selenium

Automation of web based admin tasks!

Creation of dataReading of records on the browserUpdating of contentDeletion of records

Page 12: Web testing with Selenium

What version of Selenium?

Don’t use Selenium 1.0 - Selenium IDERecorder is deprecatedJavascript Injection to drive a browser

Selenium 2 uses WebDriverhttp://docs.seleniumhq.org/projects/webdriver/

Page 13: Web testing with Selenium

WebDriver?

A platform and language-neutral interface that allows programs or scripts to introspect into, and control the behaviour of, a web browser

http://www.w3.org/TR/2013/WD-webdriver-20130117/

Page 14: Web testing with Selenium

How do I start?

Pick a language!JavaC#pythonrubyothers supported as well

Page 15: Web testing with Selenium

Pick your browser/driver

FirefoxChromeIESafarimany more!

Page 16: Web testing with Selenium

How do I interact with the browser?

Dev tools are built-in to browsersInspect the HTML to glean the locators to use

var inputElement = driver.FindElement(By.Name("myButton"));

inputElement.Click();

Page 17: Web testing with Selenium

Built-in locators

Use these if you candriver.FindElement(By.Name("myName"));

driver.FindElement(By.Id("myId"));

driver.FindElement(By.ClassName("myClass"));

others as well

Page 18: Web testing with Selenium

XPath vs. CSS

XPath//div[. ='Some Text of the Div']

CSStable[id='tblBadgeInfo'] thead td

Speed considerations?

Page 19: Web testing with Selenium

Tips to avoid headaches….

GUI based tests sometimes thought of as fragile, brittle or unreliable

How to prevent your Selenium automation from becoming shelfware

Page 20: Web testing with Selenium

Use unique locators

Very difficult if locators are not unique

Avoid using index numbers

Ask for some name/id/class on UI elements from the development team

Page 21: Web testing with Selenium

Do not use hard coded sleeps

Makes test scripts brittle when run on different environments.

Thread.Sleep(5000); // Sleep for 5 secondsbutton.Click();

Page 22: Web testing with Selenium

Use a polling wait

Be flexible and return as soon as possible but ignore exceptions

Page 23: Web testing with Selenium

Use WebDriverWait

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>

{return

d.FindElement(By.Id("myButtonId"));});

Page 24: Web testing with Selenium

Use ExpectedConditions

Convenience methods on things that are checked often. Use these with WebDriverWait.

http://selenium.googlecode.com/git/docs/api/dotnet/html/AllMembers_T_OpenQA_Selenium_Support_UI_ExpectedConditions.htm

Page 25: Web testing with Selenium

Use Page Objects

Isolate UI elements from the test cases

If the UI changes, your tests only need to be modified in a single place - the Page Object that defines the UI

Reduces duplicate code

Page 26: Web testing with Selenium

Login Page Example

Page 27: Web testing with Selenium

Login Page Objectclass LoginPage : BasePage {public LoginPage() {}public void Login(string username,string password) {var nameElement = driver.FindElement(By.Name("username"));nameElement .SendKeys(username);var passElement = driver.FindElement(By.Name("password"));passElement .SendKeys(password);var submitButton = driver.FindElement(By.Name("submit"));

submitButton.Click();}

}

Page 28: Web testing with Selenium

Login Test Case

var loginPage = new LoginPage();loginPage.Login("user","pass");

Page 29: Web testing with Selenium

Verify your assumptions….

Are you where you think you are?Verify page elements on transitionsClicked linksForm submission

Page 30: Web testing with Selenium

Be Generous with your logging

Overlogging is better than underloggingEasier to examine output files to see where

failures are occurringEspecially true for remote executionUse logging to get a trail on most events

Page 31: Web testing with Selenium

Things I like to log

URL of the pageTimestampValues used on assertionsValues used on comparatorsValues used on loops

Page 32: Web testing with Selenium

IE Considerations

Sometimes click appears to do “nothing”

Use SendKeys instead of Click

https://www.google.com/webhp?#safe=off&q=ie+click+selenium

Page 33: Web testing with Selenium

SendKeys Code

Instead ofbutton.Click();

Usebutton.SendKeys(Keys.Enter);

Page 34: Web testing with Selenium

Handling Frames

Be sure to set the focus to the frame hosting your elements.

IWebElement mainFrame =driver.FindElement(By.Name("MainFrame"));

driver.SwitchTo().Frame(mainFrame);

Page 35: Web testing with Selenium

Handling Dialogs

Javascript alertsJavascript confirm Javascript prompts

Page 36: Web testing with Selenium

Example code

try {driver.SwitchTo().Alert();return true;}catch (NoAlertPresentException) {// Modal dialog not displayedreturn false;}

Page 37: Web testing with Selenium

Handling Popup windowsvar windowHandles = driver.WindowHandles;

// if handle 0 is the main window then handle 1 is the popup, otherwise the popup is handle 0

var popUp = (windowHandles[0] == mainWindowHandle ? windowHandles[1] : windowHandles[0]);

driver.SwitchTo().Window(popUp);<do stuff>driver.SwitchTo().Window(mainWindowHandle );

Page 38: Web testing with Selenium

Not the only answer...

Sometimes Selenium can’t do the job.AutoIt can be used as a fall-back.

https://www.autoitscript.com/site/autoit/

Page 39: Web testing with Selenium

Browser login prompts

Page 40: Web testing with Selenium

Advanced Topics

Use with Continuous Integration tools

Remote control of tests

Selenium Grid

Page 41: Web testing with Selenium

Summary

Instrument your framework correctly and Selenium tests can be very good for you

Don’t be discouraged. Try different things.

Investigate to see what Selenium can do for you

Page 42: Web testing with Selenium

Contact Info

Email: [email protected]: https://www.linkedin.com/in/arkie

Come visit: http://bscwest.techwell.com/

Page 43: Web testing with Selenium

Post your questions on Twitter and we'll answer them @XBOSoft

Join us to keep updated on all our webinars, reports and whitepapers:

facebook.com/xbosoft

+xbosoft

linkedin.com/company/xbosoft

We post regularly on our blog – check us out! http://xbosoft.com/software-quality-blog/

Why not download our free Whitepapers, available here: http://xbosoft.com/knowledge-center/

You will receive an email with information on slides and recording. Any further queries regarding our services or ideas for

future webinars please email us! [email protected]

Q+A

www.xbosoft.com