+ All Categories
Home > Technology > Automated Web Testing Using Selenium

Automated Web Testing Using Selenium

Date post: 18-Jan-2017
Category:
Upload: weifeng-zhang
View: 7,507 times
Download: 1 times
Share this document with a friend
26
Transcript
Page 1: Automated Web Testing Using Selenium
Page 2: Automated Web Testing Using Selenium

Automated Web Testing using Selenium

Perficient ChinaWaylon Zhang

Yahoo!m: [email protected]

Page 3: Automated Web Testing Using Selenium

Agenda

Warm-up Introduction of Selenium FrameworkTroubleshooting of SeleniumPracticeQ&A

Page 4: Automated Web Testing Using Selenium

Warm-up

Google Advance Search Function

Page 5: Automated Web Testing Using Selenium

Prerequisite

Development experience in Java languageKnowledge of Xpath languageBasic knowledge of HTML/Junit/TestNgKnowledge of The Same Origin Policy

Page 6: Automated Web Testing Using Selenium

What is Selenium?

Selenium is a suite of tools to automate web app testing across many platforms.

– Selenium Core: DHTML test execution framework

– Selenium IDE: Firefox extension – record and playback

– Selenium Remote Control• Server: launches/kills browser,

HTTP Proxy• Client libraries

– Selenium Grid• Run Selenium tests in parallel

Page 7: Automated Web Testing Using Selenium

Selenium components

Selenium Core Selenium IDE Selenium Remote Control

Browsers Firefox, IE,Safari Firefox Firefox, IE,Safari

AUT Server side installed

Yes No No

Support Https/SSL Yes Yes Yes

Different Domain No Yes Yes

Need Jre No No Yes

Support I&O No No Yes

Programming Languages

*Selenese Selenese C#, Java, Perl, PHP, Python, Ruby

*Selenese is the set of Selenium Commands that run you tests. Don’t support If or For (While) statements

Page 8: Automated Web Testing Using Selenium

How to use Selenium RC to develop

Prepare environment

Record Refactor Run

Setup J reSelenium RC

Selenium IDEFireFox

Selenium- IDEManual Test once

Start Selenium Server

FireBugWeb Developer

Check Test Report

Page 9: Automated Web Testing Using Selenium

How Selenium RC Works?

Page 10: Automated Web Testing Using Selenium

How Selenium RC Works? (cont.)

Page 11: Automated Web Testing Using Selenium

Selenium Solutions of HTTPS

Support HTTPS– IE (supported by

default, configure IE browser)

– FireFox (Selenium server doesn’t support add-ons configurations)

– Safari (doesn’t support HTTPS configurations, so Selenium can’t run on it)

Page 12: Automated Web Testing Using Selenium

Selenium to Test Click Flash (1/2)

You can't get object via Selenium IDE

Page 13: Automated Web Testing Using Selenium

Selenium to test Click Flash (2/2)

Get help from Developer– javascript:WTKSendFlashClick( "{\"Page\":\"Exterior\", \"ClickType\":\"angleC

lick\",\"ClickParams\":{\"Direction\":\"left\"}}" )Use Selenium’s API

– selenium.runScript(target)

Page 14: Automated Web Testing Using Selenium

Selenium to test Ajax

Wait For It…

public void waitForElementPresent(String vp, String target, String friendlyMessage) {for (int second = 0;second<WAIT; second++) {if (second >= WAIT) { //fail("timeout");log.info(vp+ " - Time out, trying again while waiting for element to load: " + target);}try { if (selenium.isElementPresent(target)) break; } catch (Exception e) {}try {Thread.sleep(SPEED);} catch (InterruptedException e) {// TODO Auto-generated catch blockif (e.getMessage().indexOf("Current window or frame is closed")>-1)restartSelenium();resultLoger.result(vp, FAILURE, friendlyMessage + ". "+ "Timeout waiting for target:

"+target + ": "+e.getMessage());log.info(vp, new SeleniumException("Timeout waiting for target: "+target));}}

Wait and verify the value until time out

Page 15: Automated Web Testing Using Selenium

Add API to Selenium (1/2)

Example: add Function of getTableRows(locator) to Selenium– Server Side

• Add js to user-extensions.js• Save the user-extensions.js under the folder where selenium server

resides• start selenium server with user-extensions.js

Page 16: Automated Web Testing Using Selenium

Add API to Selenium (2/2)

Example: add Function of getTableRows(locator) to Selenium– Client Side

• Add API to Selenium.java under package of com.thoughtworks.selenium • Add function to DefaultSelenium.java under package of

com.thoughtworks.selenium

Page 17: Automated Web Testing Using Selenium

Selenium Open Issues

How to test GWT web applications?

Page 18: Automated Web Testing Using Selenium

Problems in Selenium

Verbose – Locators everywhere

Coupling– UI locators, actions, and assertions are coupled

Not expressive– What does the UI look like?

Speed– Since IE is lack of native XPath support, so tests run in IE are very slow

Record and Play– Re-labeling a button or moving it to another part of the window may

require the test to be re-recordedRefactor

– Seems to be difficultReusable

– Less likely

Page 19: Automated Web Testing Using Selenium

Tellurium’s solutionpackage com.perficient.tellurium.webapp.ui

import org.tellurium.dsl.DslContextpublic class TelluriumModule extends DslContext {

public void defineUi(){ ui.Container(uid: "root", clocator: [tag: "table", name: "Tellurium"]){ InputBox(uid: "firstName", clocator: [tag: "input", type: "text", name: "FirstName"]) InputBox(uid: "lastName", clocator: [tag: "input", type: "text", name: "LastName"]) InputBox(uid: "fullName", clocator: [tag: "input", type: "text", name: "FullName"]) InputBox(uid: "save", clocator: [tag: "input", type: "button", value: "Save"], respond: ["click"]) } } public void getFullName(String firstName,String lastName){ type "root.firstName",firstName type "root.lastName",lastName pause 500 click "root.save" }}

Page 20: Automated Web Testing Using Selenium

What is Tellurium?

UI module based web testing framework built on top of SeleniumUI is defined in Groovy class and tests can be written in

– Java (JUnit 4 or TestNG)– Groovy– Pure DSL script

Handles the mapping from Java object to UI

Reference: Reference: http://code.google.com/p/aost/

Page 21: Automated Web Testing Using Selenium

What challenges are addressed in Tellurium

No longer “record and play” style, but UI module orientedSeparatedRobustEasy to refactor

Page 22: Automated Web Testing Using Selenium

What challenges are addressed in Tellurium

Support jQuery Selector– useJQuerySelector()– disableJQuerySelector()

Page 23: Automated Web Testing Using Selenium

Summarization: Advantage/Disadvantage

Pre-condition Advantage DisadvantageSelenium It’s required to

have both the HTML and the back-end code ready before we start scripting

Record and Play requires little or no software development

Hard to refactorVery slow in IEUI locators, actions, and assertions are coupled

Tellurium Ideally only defining the HTML elements is required as the entry criteria of scripting

No longer “record and play” style, but UI module orientedEasy to refactorEasy to useUI and tests are separatedFaster performance in IE

Involved new language Very new, some potential risks we don’t know

Page 24: Automated Web Testing Using Selenium

Best Practices

To Automate or Not to Automate? That is the Question!The test framework should be approved, documented, reviewed.Structure scripts with minimal dependencies.Test automation is a fulltime effort, not a sideline. A dedicated

team is required.

Page 25: Automated Web Testing Using Selenium

Q&A

Page 26: Automated Web Testing Using Selenium

References

Tellurium Framework– http://code.google.com/p/aost/

Guidelines for Automation framework design– http://knowledgeinbox.com/articles/automation/frameworks/guidel

ines-for-automation-framework-design/10 Step Test Automation Approach - Guide for automation

testers– http://testing.thoughtworks.com/article10step


Recommended