Get Started With Selenium 3 and Selenium 3 Grid

  • View
    908

  • Download
    0

Embed Size (px)

Text of Get Started With Selenium 3 and Selenium 3 Grid

PowerPoint Presentation

Daniel Herkendherken@browseemall.comhttp://www.browseemall.comGet Started With Selenium 3Selenium 3

Today we will coverWhat is Selenium?How to setup a testing environmentRunning your first testWorking with Selenium GridSimplify with the BrowseEmAll GridQ/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:

JavaC#RubyPythonJavaScriptPerl (third-party)PHP (third-party)

What is Selenium?Which programming languages are supported?

Install Firefox: https://www.mozilla.orgInstall Google Chrome: https://www.google.com/chrome/browser/desktop/Add c:\Selenium (or similar path on macOS / Linux) to your PATH

Setup SeleniumRequirements

Internet Explorer Driver:Download (32bit or 64bit) http://www.seleniumhq.org/download/Extract to c:\SeleniumEdge Driver:Download https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/Copy to c:\SeleniumChrome Driver:Download https://sites.google.com/a/chromium.org/chromedriver/Copy to c:\SeleniumFirefox Driver:Download https://github.com/mozilla/geckodriver/releasesExtract to c:\Selenium

Setup SeleniumInstalling Drivers

A Simple TestRunning a simple Google query[TestMethod] publicvoidGoogleForSelenium() { //LaunchnewinstanceforFirefox IWebDriverdriver=newFirefoxDriver();

//Navigatetogoogle driver.Navigate().GoToUrl("http://www.google.com");

//Findtheinputfieldforthesearchquery IWebElementinputField=driver.FindElement(By.Name("q"));

//Addsometexttotheinputfield inputField.SendKeys("Selenium");

//Submitthesearch inputField.Submit();

//GoogleusesJStorendertheresultspagesoweneedtowait varwait=newWebDriverWait(driver,TimeSpan.FromSeconds(10)); wait.Until(o=>o.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//Useassertslikeyouwouldinunittests Assert.IsTrue(driver.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//closedownthebrowser driver.Quit(); }

A Simple TestDemo

A Simple Test

[TestMethod] publicvoidGoogleForSelenium_Chrome() { IWebDriverdriver=newChromeDriver(); GoogleForSelenium(driver); }

[TestMethod] publicvoidGoogleForSelenium_Edge() { IWebDriverdriver=newEdgeDriver(); GoogleForSelenium(driver); }

[TestMethod] publicvoidGoogleForSelenium_InternetExplorer() { IWebDriverdriver=newInternetExplorerDriver(); GoogleForSelenium(driver); }

publicvoidGoogleForSelenium(IWebDriverdriver) {

//Navigatetogoogle driver.Navigate().GoToUrl("http://www.google.com");

A Simple TestDemo

Selenium Grid can be used to run Selenium tests parallel and on multiple machines. This helps with:

Reducing the overall time of test executionRunning tests against browsers on different operating systems

Selenium GridWhat is Selenium Grid?

Selenium GridYour Code

Selenium GridHow does it work?Your Code

RemoteDriver

Selenium GridHow does it work?Your Code

RemoteDriver

SeleniumHub

Selenium GridHow does it work?Your Code

RemoteDriver

SeleniumHub

Selenium Node

Selenium Node

SeleniumNode

Download Java: https://www.java.com/en/download/

Download Selenium Standalone Server: http://www.seleniumhq.org/download/Copy to c:\Selenium

Start the Hub with the command line:java -jar selenium-server-standalone-3.0.1.jar -role hub

Grid console available at: http://localhost:4444/grid/console

Selenium GridSetup a Hub

Create a node configuration file:{"capabilities": [{ "browserName": "firefox", "platform": "WINDOWS", "maxInstances": 1 }],"maxSession": 5,"port": 5555,"register": true}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 GridSetup a Node

Selenium Grid

[TestMethod] publicvoidGoogleForSeleniumOnGrid() { //LaunchnewinstanceforFirefox IWebDriverdriver=newRemoteWebDriver(newUri("http://localhost:4444/wd/hub"),DesiredCapabilities.Firefox());

//Navigatetogoogle driver.Navigate().GoToUrl("http://www.google.com");

//Findtheinputfieldforthesearchquery IWebElementinputField=driver.FindElement(By.Name("q"));

//Addsometexttotheinputfield inputField.SendKeys("Selenium");

//Submitthesearch inputField.Submit();

//GoogleusesJStorendertheresultspagesoweneedtowait varwait=newWebDriverWait(driver,TimeSpan.FromSeconds(10)); wait.Until(o=>o.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//Useassertslikeyouwouldinunittests Assert.IsTrue(driver.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//closedownthebrowser driver.Quit(); }

Selenium GridDemo

BrowseEmAll Grid

BrowseEmAll Grid

[TestMethod] publicvoidGoogleForSeleniumOnGrid() { //LaunchnewinstanceforFirefox IWebDriverdriver=newRemoteWebDriver(newUri("http://localhost:4444/wd/hub"),DesiredCapabilities.Firefox());

//Navigatetogoogle driver.Navigate().GoToUrl("http://www.google.com");

//Findtheinputfieldforthesearchquery IWebElementinputField=driver.FindElement(By.Name("q"));

//Addsometexttotheinputfield inputField.SendKeys("Selenium");

//Submitthesearch inputField.Submit();

//GoogleusesJStorendertheresultspagesoweneedtowait varwait=newWebDriverWait(driver,TimeSpan.FromSeconds(10)); wait.Until(o=>o.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//Useassertslikeyouwouldinunittests Assert.IsTrue(driver.Title.StartsWith("Selenium",StringComparison.OrdinalIgnoreCase));

//closedownthebrowser driver.Quit(); }

BrowseEmAll GridDemo

Questions?Q & A