Date post: | 12-Apr-2017 |
Category: |
Technology |
Upload: | anuradha-malalasena |
View: | 167 times |
Download: | 0 times |
Selenium Automation
Anuradha Malalasena
Overview■ Part 1
– Why Automated testing?– Why Selenium?– History of Selenium– Selenium IDE
■ Part 2– Selenium WebDriver– Setup Development Environment (.net)– Design Patterns
PART-ONE
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.
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.
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
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.
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”.
Selenium Projects
Selenium IDE
Selenium WebDriver
Selenium Grid
Selenium RC
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
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
Install Selenium IDE
■ Install Firefox■ Go to http://www.seleniumhq.org/download/■ Install Selenium Add-ons■ Restart Browser
Other Tools
■ Firebug■ Firefinder■ IE Developer Tool■ Google Chrome Developer Tool
Selenium IDE Walkthrough
■ Selenium 2 Testing Tools Beginner's Guide– David Burns
Reference
DEMO
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/
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/
Things not Possible
■ Silverlight and Flex/Flash applications■ HTML5 is not fully supported with Selenium IDE.
– contentEditable=true
Recommended For
■ Create quick bug reproduction scripts■ Create scripts to aid in automation-aided exploratory testing
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
Questions ?
Thank You !
PART-TWO
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
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.
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
Related Libraries and
Solution Structure
DEMO
Design Patterns
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"));}
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"); }
DEMO
Questions ?
Thank You !