gems of selenium

33
@testinggeek www.TestingGeek.com Gems of Selenium Anand Ramdeo Komal Joshi

Upload: skills-matter

Post on 16-Apr-2017

2.981 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Gems Of Selenium

@testinggeek www.TestingGeek.com

Gems of Selenium

Anand Ramdeo

Komal Joshi

Page 2: Gems Of Selenium

Selenium Is..

www.atlantissw.com | www.TestingGeek.com

Page 3: Gems Of Selenium

A bit of History..

www.atlantissw.com | www.TestingGeek.com

SELENIUM

Page 4: Gems Of Selenium

It All Started Here• Time and Expense application built using

Python+Plone @ Thoughtworks• Goal was “Fast, Fast, Fast”

www.atlantissw.com | www.TestingGeek.com

ADD ROW

Page 5: Gems Of Selenium

It All Started Here

• Time and Expense application built using Python+Plone @ Thoughtworks

• Goal was “Fast, Fast, Fast”

www.atlantissw.com | www.TestingGeek.com

ADD ROW

Page 6: Gems Of Selenium

It All Started Here

• Time and Expense application built using Python+Plone @ Thoughtworks

• Goal was “Fast, Fast, Fast”

www.atlantissw.com | www.TestingGeek.com

ADD ROW

Page 7: Gems Of Selenium

Problems..

www.atlantissw.com | www.TestingGeek.com

Page 8: Gems Of Selenium

And Solutions..

• Mozilla Extension – “Driftwood” by Andrew McCormick from Thoughtworks. Worked, but it was firefox only solution.

• Paul Gross and Jasson Huggin set out to implement Fit for JS.

• Which eventually became Selenium Core or Java Script Test Runner

www.atlantissw.com | www.TestingGeek.com

Page 9: Gems Of Selenium

Popularity of Selenium

www.atlantissw.com | www.TestingGeek.com

Page 10: Gems Of Selenium

Reason of Success

www.atlantissw.com | www.TestingGeek.com

Page 11: Gems Of Selenium

@testinggeek www.TestingGeek.com

In search of treasure

The journey begins..•Want to automate ? •What are the common problems faced by people when using selenium IDE?

Page 12: Gems Of Selenium

@testinggeek www.TestingGeek.com

In search of treasureTreasure is ….•Reliable automation.•Stable automation.•Maintainable automation.•Effective Automation.

Page 13: Gems Of Selenium

@testinggeek www.TestingGeek.com

Found my first Gem….UI Element

How can this precious gem help me?

Page 14: Gems Of Selenium

@testinggeek www.TestingGeek.com

UI Element is...

• • ...a mapping between semantically meaningful names of elements on webpages, and the elements.

...defined using JSON

Page 15: Gems Of Selenium

@testinggeek www.TestingGeek.com

Abstraction With UI-Element selenium.type("q", “TestingGeek"); selenium.click("btnG");

LOGIN_BUTTON = "css=input[value='Log in']"DELETE_CONFIRMATION = "css=input[value='\"Yes, I'm sure\"']"

myMap.addPageset({    name: 'allPages',    description: 'All WLL Pages',    pathRegexp: '.*'});

myMap.addElement ('allPages', {    name: 'register'    , description: 'Register link on all the pages'    , locator: "xpath=//*[@id='user']/dd/a[1]"    })

sel.click("ui=allPages::register()")

Abstracting with UI Element

Page 16: Gems Of Selenium

@testinggeek www.TestingGeek.com

I want to extend Selenium with some new assertions,actions

No problem User-extension.js is here for that.

Page 17: Gems Of Selenium

@testinggeek www.TestingGeek.com

Extending Slenium...

Selenium Object PrototypePagebot Object Prototype.On startup, Selenium will automatically look

through methods on these prototypes, using name patterns to recognize which ones are actions, assertions and locators.

Page 18: Gems Of Selenium

@testinggeek www.TestingGeek.com

Automation is incomplete without cross browser testing

Selenium RC gem for different browser…• * iehta• * firefox• * iexplore• * chrome• * custom (for custom browsers)

Page 19: Gems Of Selenium

@testinggeek www.TestingGeek.com

https...

Different options of selenium…- https- Multiwindow=<true/false>- Firefoxtemplate=<default template

location>

Page 20: Gems Of Selenium

@testinggeek www.TestingGeek.com

Collecting all the gems and putting in the treasure chest

Page 21: Gems Of Selenium

@testinggeek www.TestingGeek.com

Is this the only treasure• The real gems are in your minds in your brains.• Come up with a solution• Implement a simple but effective solution.

Page 22: Gems Of Selenium

@testinggeek www.TestingGeek.com

Automate using wrappers.

SA

Use a combination of tools....• Selenium + Auto it.• Selenium + Batch files.

Page 23: Gems Of Selenium

@testinggeek www.TestingGeek.com

SA

/** * This method would just kill the PDF*/

public void closesPDF(){{

String[] dialog = new String[] { "src\\test\\resources\\KillAcroRd32.bat"};try {

Process p = Runtime.getRuntime().exec(dialog);System.out.println(p.getErrorStream().toString());System.out.println(p.getInputStream().toString());System.out.println(p.getOutputStream().toString());System.out.println("After execution");

} catch (IOException e) {// TODO Auto-generated catch blockSystem.out.println("In the exception");e.printStackTrace();throw new AssertionError("No Dialogue box displayed");

} }

}

Page 24: Gems Of Selenium

@testinggeek www.TestingGeek.com

Easy to read Natural language automation• Simple easy to read language

• POM.

Page 25: Gems Of Selenium

@testinggeek www.TestingGeek.com

Componentise your automation

Page 26: Gems Of Selenium

@testinggeek www.TestingGeek.com

Add dynamism...

Connecting to the databses…

Page 27: Gems Of Selenium

@testinggeek www.TestingGeek.com

All this is less effective if automation does not run automatically......

Page 28: Gems Of Selenium

@testinggeek www.TestingGeek.com

Integrate with CI tools

Mavenise your automation... And integrate them with Hudson...

Page 29: Gems Of Selenium

@testinggeek www.TestingGeek.com

Distribute the Tests

With Selenium Grids or

Hudson Slaves...

Page 30: Gems Of Selenium

@testinggeek www.TestingGeek.com

Integrate with CI tools

What about Selenium 2.0 ?.....

Will my old selenium tests run in 2.0?

Page 31: Gems Of Selenium

@testinggeek www.TestingGeek.com

Selenium 2.0

-Web Driver- Presentation redering etc.

Page 32: Gems Of Selenium

@testinggeek www.TestingGeek.com

import java.util.List;

import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.RenderedWebElement;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;

public class TestingGeek {

public static void main(String[] args) throws Exception { // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver();

// Go to the TestingGeek home page driver.get("http://www.testinggeek.com");

// Enter the query string "Cheese" //WebElement query = driver.findElement(By.name("q")); WebElement menu= driver.findElement(By.id("menu27")); menu.click(); // query.sendKeys("Cheese");

// Sleep until the div we want is visible or 5 seconds is over long end = System.currentTimeMillis() + 5000; while (System.currentTimeMillis() < end) { // Browsers which render content (such as Firefox and IE) // return "RenderedWebElements" // RenderedWebElement resultsDiv = (RenderedWebElement) driver.findElement(By.className("gac_m")); RenderedWebElement resultsDiv = (RenderedWebElement) driver.findElement(By. id("menu27")); // If results have been returned, // the results are displayed in a drop down. if (resultsDiv.isDisplayed()) { break; } }

// And now list the suggestions //List<WebElement> allSuggestions = driver.findElements(By.xpath("//td[@class='gac_c']")); List<WebElement> menus = driver.findElements(By.xpath("//div/div/div/ul/li[2]/ul")); for (WebElement menu1 : menus) { System.out.println(menu1.getText()); } }

}

Page 33: Gems Of Selenium

@testinggeek www.TestingGeek.com

Thank You.

Anand Ramdeo

www.TestingGeek.com@testinggeek

www.AtlantisSw.com

[email protected]