get started with selenium 3 and selenium 3 grid

28
Daniel Herken [email protected] http://www.browseemall.com Get Started With Selenium 3 Selenium 3

Upload: daniel-herken

Post on 16-Apr-2017

928 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Get Started With Selenium 3 and Selenium 3 Grid

Daniel [email protected]://www.browseemall.com

Get Started With Selenium 3

Selenium 3

Page 2: Get Started With Selenium 3 and Selenium 3 Grid

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

Page 3: Get Started With Selenium 3 and Selenium 3 Grid

Supported by all major browser vendors:

What is Selenium?

Free and open source browser automation framework.

Page 4: Get Started With Selenium 3 and Selenium 3 Grid

What is Selenium?

How does it work?

Your Code

Page 5: Get Started With Selenium 3 and Selenium 3 Grid

What is Selenium?

How does it work?

Your Code Selenium

Page 6: Get Started With Selenium 3 and Selenium 3 Grid

What is Selenium?

How does it work?

Your Code Selenium

IEDriver

EdgeDriver

FirefoxDriver

ChromeDriver

Page 7: Get Started With Selenium 3 and Selenium 3 Grid

What is Selenium?

How does it work?

Your Code Selenium

IEDriver

EdgeDriver

FirefoxDriver

ChromeDriver

Internet Explorer

MicrosoftEdge

Firefox

Chrome

Page 8: Get Started With Selenium 3 and Selenium 3 Grid

Supports automation of all major browsers:

What is Selenium?

Which browsers are supported?

Page 9: Get Started With Selenium 3 and Selenium 3 Grid

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?

Page 10: Get Started With Selenium 3 and Selenium 3 Grid

• 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

Page 11: Get Started With Selenium 3 and Selenium 3 Grid

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

Page 12: Get Started With Selenium 3 and Selenium 3 Grid

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(); }

Page 13: Get Started With Selenium 3 and Selenium 3 Grid

A Simple Test

Demo

Page 14: Get Started With Selenium 3 and Selenium 3 Grid

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");

Page 15: Get Started With Selenium 3 and Selenium 3 Grid

A Simple Test

Demo

Page 16: Get Started With Selenium 3 and Selenium 3 Grid

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?

Page 17: Get Started With Selenium 3 and Selenium 3 Grid

Selenium Grid

Your Code

Page 18: Get Started With Selenium 3 and Selenium 3 Grid

Selenium Grid

How does it work?

Your Code RemoteDriver

Page 19: Get Started With Selenium 3 and Selenium 3 Grid

Selenium Grid

How does it work?

Your Code RemoteDriver

SeleniumHub

Page 20: Get Started With Selenium 3 and Selenium 3 Grid

Selenium Grid

How does it work?

Your Code RemoteDriver

SeleniumHub

Selenium Node

Selenium Node

SeleniumNode

Page 21: Get Started With Selenium 3 and Selenium 3 Grid

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

Page 22: Get Started With Selenium 3 and Selenium 3 Grid

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

Page 23: Get Started With Selenium 3 and Selenium 3 Grid

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(); }

Page 24: Get Started With Selenium 3 and Selenium 3 Grid

Selenium Grid

Demo

Page 25: Get Started With Selenium 3 and Selenium 3 Grid

BrowseEmAll Grid

Page 26: Get Started With Selenium 3 and Selenium 3 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(); }

Page 27: Get Started With Selenium 3 and Selenium 3 Grid

BrowseEmAll Grid

Demo

Page 28: Get Started With Selenium 3 and Selenium 3 Grid

Questions?

Q & A