+ All Categories
Home > Technology > Selenium Automation

Selenium Automation

Date post: 12-Apr-2017
Category:
Upload: anuradha-malalasena
View: 167 times
Download: 0 times
Share this document with a friend
35
Selenium Automation Anuradha Malalasena
Transcript
Page 1: Selenium Automation

Selenium Automation

Anuradha Malalasena

Page 2: Selenium Automation

Overview■ Part 1

– Why Automated testing?– Why Selenium?– History of Selenium– Selenium IDE

■ Part 2– Selenium WebDriver– Setup Development Environment (.net)– Design Patterns

Page 3: Selenium Automation

PART-ONE

Page 4: Selenium Automation

What is Automated testing ?

■ Test automation is the use of special software to control the execution of tests and the comparison of actual outcomes with predicted outcomes.

Page 5: Selenium Automation

Why Automated testing ?

Manual Testing Automated Testing

Manual testing is not accurate at all times due to human error.

Automated testing is more reliable, as it is performed by tools.

Manual testing is time-consuming, taking up human resources.

Automated testing is executed by software tools, so it is significantly faster.

Investment is required for human resources. Investment is required for testing tools.

Manual testing is only practical when frequent repetition is not required.

Automated testing is a practical option when the test cases are run repeatedly over a long time period.

Page 6: Selenium Automation

Why Selenium ?

■ Selenium,– is free and open source– has a large user base and helping communities– has cross Browser compatibility (Firefox, chrome, Internet

Explorer, Safari etc.)– has great platform compatibility (Windows, Mac OS, Linux etc.)– supports multiple programming languages (Java, C#, Ruby,

Python, Pearl etc.)– supports distributed testing

Page 7: Selenium Automation

History of Selenium■ In 2004, at ThoughtWorks, Jason Huggins built the “Selenium

Core” model.– It is limited by the JavaScript sandbox in browsers.

■ Paul Hammant joined the team and steered the second phase of selenium development.– Code with your favorite computer language

■ In 2005, at ThoughtWorks released Selenium RC.■ In 2007, Huggins joined Google and keep improving the

Selenium RC.■ In 2007, at ThoughtWorks, Simon Stewart developed a superior

browser automation tool called WebDriver.■ In 2009, they decided to merge two projects and call the new

project Selenium WebDriver.

Page 8: Selenium Automation

The name Selenium comes from a joke made by Huggins in an email, mocking a competitor named Mercury, saying that,

“You can cure mercury poisoning by taking selenium supplements”.

Page 9: Selenium Automation

Selenium Projects

Selenium IDE

Selenium WebDriver

Selenium Grid

Selenium RC

Page 10: Selenium Automation

Selenium RC

■ Selenium RC comes in two parts. – Client libraries for your favorite

computer language■ Java / C# / Python / Ruby / Perl / PHP

– Selenium Server which Interprets and runs the Selenese commands■ Automatically launches and kills

browsers■ Acts as a HTTP proxy for web requests

Page 11: Selenium Automation

Selenium IDE

■ Selenium IDE is a Firefox Add-on originally developed by Shinya Kasatani

■ Selenium IDE was developed to help testers to record and play back their actions

■ 140 long API commands

Page 12: Selenium Automation

Install Selenium IDE

■ Install Firefox■ Go to http://www.seleniumhq.org/download/■ Install Selenium Add-ons■ Restart Browser

Page 13: Selenium Automation

Other Tools

■ Firebug■ Firefinder■ IE Developer Tool■ Google Chrome Developer Tool

Page 14: Selenium Automation

Selenium IDE Walkthrough

Page 15: Selenium Automation

■ Selenium 2 Testing Tools Beginner's Guide– David Burns

Reference

Page 16: Selenium Automation

DEMO

Page 17: Selenium Automation

Demo Schedule ■ My first record and playback■ Locators

– Locate elements by ID– Locate elements by Name– Locate elements by Link– Locate elements by Xpath

■ XPath uses path expressions to select nodes or node-sets in an XML document.– Locate elements by CSS

■ In CSS, selectors are patterns used to select the element(s) you want to style.– Locate elements by DOM

■ When a web page is loaded, the browser creates a Document Object Model of the page.■ The HTML DOM model is constructed as a tree of Objects:

■ Add assertion– Assert vs Verify

■ Add comments

http://book.theautomatedtester.co.uk/

Page 18: Selenium Automation

Demo Schedule (cont..)

■ Handle Multiple Browser Windows■ Handle Alerts■ Working with AJAX■ Store Variable■ Debug Testing■ Create Test Suit■ Create Test Case

http://book.theautomatedtester.co.uk/

Page 19: Selenium Automation

Things not Possible

■ Silverlight and Flex/Flash applications■ HTML5 is not fully supported with Selenium IDE.

– contentEditable=true

Page 20: Selenium Automation

Recommended For

■ Create quick bug reproduction scripts■ Create scripts to aid in automation-aided exploratory testing

Page 21: Selenium Automation

Why not Selenium RC

■ Selenium RC written purely in JavaScript■ This JavaScript would automate the browser from within the browser.■ Selenium RC API has grown over the life of the project to support the

changes that have been happening to web applications (140 API calls)■ Mobile devices and HTML5 not supported

Page 22: Selenium Automation

Questions ?

Page 23: Selenium Automation

Thank You !

Page 24: Selenium Automation

PART-TWO

Page 25: Selenium Automation

Corrections

■ Source tab of Selenium IDE shows selenese commands of recording– Selenese is a HTML– http://release.seleniumhq.org/selenium-core/1.0.1/reference.html

■ Selenium RC Proxy is for internal usage

Page 26: Selenium Automation

Selenium WebDriver Architecture■ Selenium WebDriver control the browser from outside the browser.■ It controls the browser from the OS level■ It uses browser’s accessibility API to drive the browser.

– This approach means we can control browsers in the best possible way

– Firefox use JavaScript to access API. – While Internet Explorer uses C++.

■But…, new browsers entering the market will not be supported straight away.

Page 27: Selenium Automation

Environment Setup (C#.net)

■ Visual Studio■ Install browser specific drivers

– No need for Firefox– Add driver location to Path variable and

■ IE11 related registry key changes– https://

code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration

■ Restart the PC

Page 28: Selenium Automation

Related Libraries and

Solution Structure

Page 29: Selenium Automation

DEMO

Page 30: Selenium Automation

Design Patterns

Page 31: Selenium Automation

Page Object Pattern■ Page Object simply models UI areas as objects within the test code.■ This reduces the amount of duplicated codes.■ Try and think about the services that they're interacting with rather

than the implementation■ Methods on the PageObject should return other PageObjects.

■ Test should be responsible for making assertions (not the PageObjects)

public class LoginPage {    public HomePage loginAs(String username, String password) {        // ... clever magic happens here    }}

public void testMessagesAreReadOrUnread() {    Inbox inbox = new Inbox(driver);    assertTrue(inbox.isMessageWithSubjectIsUnread("I like cheese"));    assertFalse(inbox.isMessageWithSubjectIsUnread("I'm not fond of tofu"));}

Page 32: Selenium Automation

PageFactory■ In order to support the PageObject pattern, WebDriver's support

library contains a factory class.public class GoogleSearchPage {    // The element is now looked up using the name attribute    @FindBy(how = How.NAME, using = "q")    private WebElement searchBox;

    public void searchFor(String text) {        // We continue using the element just as before        searchBox.sendKeys(text);        searchBox.submit();    }}

public static void main(String[] args) {        // Create a new instance of a driver        WebDriver driver = new HtmlUnitDriver();

        // Navigate to the right place        driver.get("http://www.google.com/");

        // Create a new instance of the search page class        // and initialise any WebElement fields in it.        GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);

        // And now do the search.        page.searchFor("Cheese");    }

Page 33: Selenium Automation

DEMO

Page 34: Selenium Automation

Questions ?

Page 35: Selenium Automation

Thank You !


Recommended