Today we will cover
1. What is Selenium?2. How to setup a testing environment3. Running your first test4. Working with Selenium Grid5. Simplify with the BrowseEmAll Grid6. Q/A Session
Introduction
Supported by all major browser vendors:
What is Selenium?
Free and open source browser automation framework.
What is Selenium?
How does it work?
Your Code
What is Selenium?
How does it work?
Your Code Selenium
What is Selenium?
How does it work?
Your Code Selenium
IEDriver
EdgeDriver
FirefoxDriver
ChromeDriver
What is Selenium?
How does it work?
Your Code Selenium
IEDriver
EdgeDriver
FirefoxDriver
ChromeDriver
Internet Explorer
MicrosoftEdge
Firefox
Chrome
Supports automation of all major browsers:
What is Selenium?
Which browsers are supported?
Selenium language bindings are available for:
• Java• C#• Ruby• Python• JavaScript• Perl (third-party)• PHP (third-party)
What is Selenium?
Which programming languages are supported?
• Install Firefox: https://www.mozilla.org• Install Google Chrome: https://www.google.com/chrome/browser/desktop/• Add c:\Selenium (or similar path on macOS / Linux) to your PATH
Setup Selenium
Requirements
o Internet Explorer Driver:• Download (32bit or 64bit) http://www.seleniumhq.org/download/• Extract to c:\Selenium
o Edge Driver:• Download https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/• Copy to c:\Selenium
o Chrome Driver:• Download https://sites.google.com/a/chromium.org/chromedriver/• Copy to c:\Selenium
o Firefox Driver:• Download https://github.com/mozilla/geckodriver/releases• Extract to c:\Selenium
Setup Selenium
Installing Drivers
A Simple Test
Running a simple Google query[TestMethod] public void GoogleForSelenium() { // Launch new instance for Firefox IWebDriver driver = new FirefoxDriver();
// Navigate to google driver.Navigate().GoToUrl("http://www.google.com");
// Find the input field for the search query IWebElement inputField = driver.FindElement(By.Name("q"));
// Add some text to the input field inputField.SendKeys("Selenium");
// Submit the search inputField.Submit();
// Google uses JS to render the results page so we need to wait var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(o => o.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// Use asserts like you would in unit tests Assert.IsTrue(driver.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// close down the browser driver.Quit(); }
A Simple Test
Demo
A Simple Test[TestMethod] public void GoogleForSelenium_Chrome() { IWebDriver driver = new ChromeDriver(); GoogleForSelenium(driver); }
[TestMethod] public void GoogleForSelenium_Edge() { IWebDriver driver = new EdgeDriver(); GoogleForSelenium(driver); }
[TestMethod] public void GoogleForSelenium_InternetExplorer() { IWebDriver driver = new InternetExplorerDriver(); GoogleForSelenium(driver); }
public void GoogleForSelenium(IWebDriver driver) {
// Navigate to google driver.Navigate().GoToUrl("http://www.google.com");
A Simple Test
Demo
Selenium Grid can be used to run Selenium tests parallel and on multiple machines. This helps with:
• Reducing the overall time of test execution• Running tests against browsers on different operating systems
Selenium Grid
What is Selenium Grid?
Selenium Grid
Your Code
Selenium Grid
How does it work?
Your Code RemoteDriver
Selenium Grid
How does it work?
Your Code RemoteDriver
SeleniumHub
Selenium Grid
How does it work?
Your Code RemoteDriver
SeleniumHub
Selenium Node
Selenium Node
SeleniumNode
1. Download Java: https://www.java.com/en/download/
2. Download Selenium Standalone Server: http://www.seleniumhq.org/download/• Copy to c:\Selenium
3. Start the Hub with the command line:• java -jar selenium-server-standalone-3.0.1.jar -role hub
4. Grid console available at: http://localhost:4444/grid/console
Selenium Grid
Setup a Hub
1. Create a node configuration file:{ "capabilities": [{ "browserName": "firefox", "platform": "WINDOWS", "maxInstances": 1 }],"maxSession": 5,"port": 5555,"register": true}
2. Start the Node with the command line:• java -jar selenium-server-standalone-3.0.1.jar -role node -hub
http://localhost:4444/grid/register -nodeConfig node.json
Selenium Grid
Setup a Node
Selenium Grid[TestMethod] public void GoogleForSeleniumOnGrid() { // Launch new instance for Firefox IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());
// Navigate to google driver.Navigate().GoToUrl("http://www.google.com");
// Find the input field for the search query IWebElement inputField = driver.FindElement(By.Name("q"));
// Add some text to the input field inputField.SendKeys("Selenium");
// Submit the search inputField.Submit();
// Google uses JS to render the results page so we need to wait var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(o => o.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// Use asserts like you would in unit tests Assert.IsTrue(driver.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// close down the browser driver.Quit(); }
Selenium Grid
Demo
BrowseEmAll Grid
BrowseEmAll Grid[TestMethod] public void GoogleForSeleniumOnGrid() { // Launch new instance for Firefox IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());
// Navigate to google driver.Navigate().GoToUrl("http://www.google.com");
// Find the input field for the search query IWebElement inputField = driver.FindElement(By.Name("q"));
// Add some text to the input field inputField.SendKeys("Selenium");
// Submit the search inputField.Submit();
// Google uses JS to render the results page so we need to wait var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(o => o.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// Use asserts like you would in unit tests Assert.IsTrue(driver.Title.StartsWith("Selenium", StringComparison.OrdinalIgnoreCase));
// close down the browser driver.Quit(); }
BrowseEmAll Grid
Demo
Questions?
Q & A