In this talk you will learn how to:
- Setup Selenium 3 execution in Chrome, Firefox, IE and Edge
- Create and run a Selenium test
- Run tests against a Selenium Grid
More webinars can be found here:
http://www.browseemall.com/Resources/Webinars
2. Today we will cover
1. What is Selenium?
2. How to setup a testing environment
3. Running your first test
4. Working with Selenium Grid
5. Simplify with the BrowseEmAll Grid
6. Q/A Session
Introduction
3. Supported by all major browser vendors:
What is Selenium?
Free and open source browser automation framework.
6. What is Selenium?
How does it work?
Your Code Selenium
IEDriver
Edge
Driver
Firefox
Driver
Chrome
Driver
7. What is Selenium?
How does it work?
Your Code Selenium
IEDriver
Edge
Driver
Firefox
Driver
Chrome
Driver
Internet
Explorer
Microsoft
Edge
Firefox
Chrome
8. Supports automation of all major browsers:
What is Selenium?
Which browsers are supported?
9. 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?
10. • 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
11. 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
12. 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();
}
14. 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");
16. 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?
20. Selenium Grid
How does it work?
Your Code
Remote
Driver
Selenium
Hub
Selenium
Node
Selenium
Node
Selenium
Node
21. 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
22. 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
23. 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();
}
26. 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();
}