selenium automation
TRANSCRIPT
![Page 1: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/1.jpg)
Selenium Automation
Anuradha Malalasena
![Page 2: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/2.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/3.jpg)
PART-ONE
![Page 4: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/4.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/5.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/6.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/7.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/8.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/9.jpg)
Selenium Projects
Selenium IDE
Selenium WebDriver
Selenium Grid
Selenium RC
![Page 10: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/10.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/11.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/12.jpg)
Install Selenium IDE
■ Install Firefox■ Go to http://www.seleniumhq.org/download/■ Install Selenium Add-ons■ Restart Browser
![Page 13: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/13.jpg)
Other Tools
■ Firebug■ Firefinder■ IE Developer Tool■ Google Chrome Developer Tool
![Page 14: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/14.jpg)
Selenium IDE Walkthrough
![Page 15: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/15.jpg)
■ Selenium 2 Testing Tools Beginner's Guide– David Burns
Reference
![Page 16: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/16.jpg)
DEMO
![Page 17: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/17.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/18.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/19.jpg)
Things not Possible
■ Silverlight and Flex/Flash applications■ HTML5 is not fully supported with Selenium IDE.
– contentEditable=true
![Page 20: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/20.jpg)
Recommended For
■ Create quick bug reproduction scripts■ Create scripts to aid in automation-aided exploratory testing
![Page 21: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/21.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/22.jpg)
Questions ?
![Page 23: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/23.jpg)
Thank You !
![Page 24: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/24.jpg)
PART-TWO
![Page 25: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/25.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/26.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/27.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/28.jpg)
Related Libraries and
Solution Structure
![Page 29: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/29.jpg)
DEMO
![Page 30: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/30.jpg)
Design Patterns
![Page 31: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/31.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/32.jpg)
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](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/33.jpg)
DEMO
![Page 34: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/34.jpg)
Questions ?
![Page 35: Selenium Automation](https://reader031.vdocument.in/reader031/viewer/2022021921/58ed702e1a28ab7c2e8b4603/html5/thumbnails/35.jpg)
Thank You !