English 中文(简体)
Selenium - Grid
  • 时间:2024-03-21 15:30:07

Selenium - Grid


Previous Page Next Page  

氯胺醇是一种工具,通过多种物理或虚拟机器传播测试,以便我们能够同时(同时)执行文字。 它通过向我们提供迅速和准确的反馈,大大加快了各行凶者和平台之间的测试过程。

Selenium Grid允许我们同时进行多种网络驱动器或Selenium遥控检测,同时使用相同的代码基数,因此该代码需要在其所实施的系统中出现NOT。 se-服务器独立包包括湖、网络驱动器和Selenium RC,以实施电网的文字。

Selenium Grid有一个枢纽和一个 No。

    也可将该中心视为一个服务器,作为触发测试的中心点。 A Selenium Grid只有一个湖,一度用一台机器发射。

    <Node-Nodes是湖中负责执行测试的ium。 一个或一个以上的节点可以由任何顾问组成,并可包含任何支持的浏览器。

Architecture

以下图表显示了Selenium Grid的结构。

selenium_ide_121

Working with Grid

为了与格里德合作,我们需要遵循某些议定书。 下文列出参与这一进程的主要步骤——

    Configuring the Hub

    Configuring the Nodes

    Develop the Script and Prepare the XML File

    Test Execution

    Result Analysis

让我们详细讨论这些步骤。

Configuring the Hub

。 如下文所示,通过点击版本下载。

selenium_ide_45

Step 2——利用以下指挥发射Selenium服务器,从湖开始。 现在,我们将利用4444号港口开始该枢纽。

java -jar selenium-server-standalone-2.25.0.jar -port 4444 -role hub -nodeTimeout 1000
selenium_ide_122

Step 3——现在开放浏览器和浏览器进入URL http/ localhost:444444 from the Hub (The system where 你已执行第2步)。

selenium_ide_123

Step 4——现在点击了Cesole链接,点击电汇。 该中心的配置如下。 时至现在,我们没有任何节点,因此我们无法看到细节。

selenium_ide_124

Configuring the Nodes

Fox 采用以下指挥系统。

java -jar D:JARselenium-server-standalone-2.42.2.jar
   -role node -hub http://10.30.217.157:4444/grid/register
   -browser browserName = firefox -port 5555

如果有,

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = firefox (Parameter to specify the Browser name on Nodes)

5555 = Port on which Firefox Node would be up and running.

selenium_ide_125

Step 3——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 而湖现在将展示其附属的节点。

selenium_ide_126

Step 4——现在让我们发射因特网探索者Node。 为了启动国际电子数据交换台,我们需要将因特网探索者驾驶员下载到点末机上。

下载因特网探索者驱动器,浏览到 并下载根据贵处结构编制的适当文件。 在你下载后,把前案卷和排在案号上,必须提一下。

selenium_ide_131

C:>java -Dwebdriver.ie.driver = D:IEDriverServer.exe
   -jar D:JARselenium-server-standalone-2.42.2.jar
   -role webdriver -hub http://10.30.217.157:4444/grid/register
   -browser browserName = ie,platform = WINDOWS -port 5558

如果有,

D:IEDriverServer.exe = The location of the downloaded the IE Driver(on the Node Machine)

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = ie (Parameter to specify the Browser name on Nodes)

5558 = Port on which IE Node would be up and running.

selenium_ide_127

Step 7——执行指挥后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示附属于它的伊埃诺德。

selenium_ide_128

我们现在要发射 Chrome。 为了启动“诺德”号,我们需要把“ Chrome”号驱动器下载到代号机器上。

接着向第三方Browser司机区航行,并点击第2.10版,如下所示。

selenium_ide_132

<Step 10——根据你的职业介绍所的类型下载驾驶员。 我们将在视窗环境中执行,因此我们将下载视窗 Chrome司机。 在你下载后,将前案卷解冻,并把它放在发射小.时必须提及的夹中。

selenium_ide_133

Step 11——利用以下指挥发射 Chrome。

C:>java -Dwebdriver.chrome.driver = D:chromedriver.exe 
   -jar D:JARselenium-server-standalone-2.42.2.jar 
   -role webdriver -hub  http://10.30.217.157:4444/grid/register 
   -browser browserName = chrome, platform = WINDOWS -port 5557

如果有,

D:chromedriver.exe = The location of the downloaded the chrome Driver(on the Node Machine)

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = chrome (Parameter to specify the Browser name on Nodes)

5557 = Port on which chrome Node would be up and running.

selenium_ide_129

Step 12——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示其附属的神hr。

selenium_ide_130

Develop the Script and Prepare the XML File

我们将利用全国测验小组进行试验。 在以下例子中,我们将利用远程网络驱动器发射每个浏览器。 它可以将其能力传给驾驶员,以便司机掌握在诺德实施的一切信息。

Browser 参数将从“XML”档案中删除。

package TestNG;

import org.openqa.selenium.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabipties;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.net.MalformedURLException;

pubpc class TestNGClass {
   pubpc WebDriver driver;
   pubpc String URL, Node;
   protected ThreadLocal<RemoteWebDriver> threadDriver = null;
   
   @Parameters("browser")
   @BeforeTest
   pubpc void launchapp(String browser) throws MalformedURLException {
      String URL = "http://www.calculator.net";
      
      if (browser.equalsIgnoreCase("firefox")) {
         System.out.println(" Executing on FireFox");
         String Node = "http://10.112.66.52:5555/wd/hub";
         DesiredCapabipties cap = DesiredCapabipties.firefox();
         cap.setBrowserName("firefox");
         
         driver = new RemoteWebDriver(new URL(Node), cap);
         // Puts an Imppcit wait, Will wait for 10 seconds before throwing exception
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else if (browser.equalsIgnoreCase("chrome")) {
         System.out.println(" Executing on CHROME");
         DesiredCapabipties cap = DesiredCapabipties.chrome();
         cap.setBrowserName("chrome");
         String Node = "http://10.112.66.52:5557/wd/hub";
         driver = new RemoteWebDriver(new URL(Node), cap);
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else if (browser.equalsIgnoreCase("ie")) {
         System.out.println(" Executing on IE");
         DesiredCapabipties cap = DesiredCapabipties.chrome();
         cap.setBrowserName("ie");
         String Node = "http://10.112.66.52:5558/wd/hub";
         driver = new RemoteWebDriver(new URL(Node), cap);
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else {
         throw new IllegalArgumentException("The Browser Type is Undefined");
      }
   }
   
   @Test
   pubpc void calculatepercent() {
      // Cpck on Math Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[3]/a")).cpck();     	
      
      // Cpck on Percent Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[4]/span[3]/a")).cpck();
      
      // Enter value 10 in the first number of the percent Calculator
      driver.findElement(By.id("cpar1")).sendKeys("10");
      
      // Enter value 50 in the second number of the percent Calculator
      driver.findElement(By.id("cpar2")).sendKeys("50");
      
      // Cpck Calculate Button
      // driver.findElement(By.xpath(".//*[@id =  content ]/table/tbody/tr/td[2]/input")).cpck();
      // Get the Result Text based on its xpath
      String result =
         driver.findElement(By.xpath(".//*[@id =  content ]/p[2]/span/font/b")).getText();
      
      // Print a Log In message to the screen
      System.out.println(" The Result is " + result);
      
      if(result.equals("5")) {
         System.out.println(" The Result is Pass");
      } else {
         System.out.println(" The Result is Fail");
      }
   }
   
   @AfterTest
   pubpc void closeBrowser() {
      driver.quit();
   }
}

将通过XML。 在该项目下设立一个XML。

selenium_ide_134

selenium_ide_135

查阅档案并点击Finish。

selenium_ide_136

Step 5——测试Ng.XML是根据项目夹创建的,如下所示。

selenium_ide_137

XML档案的内容如下。 我们制造了3个试验,并将其放在一起,并提到平行的“试验”,以便所有试验都同时进行。

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name = "Suite" parallel = "tests">

   <test name = "FirefoxTest">
   <parameter name = "browser" value = "firefox" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>

   <test name = "ChromeTest">
   <parameter name = "browser" value = "chrome" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>

   <test name = "IETest">
   <parameter name = "browser" value = "ie" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>
   
</suite>

Test Execution

Step 1——选择创建的XML;右翼和选择Rong As >> 测试NG Suite。

selenium_ide_139

我们现在开放诺德,我们在那里启动了所有浏览器点。 你们将看到所有三个浏览器同时执行。

selenium_ide_140

Result Analysis

Step 1——在完成执行时,我们可以分析结果,如任何其他执行。 定本摘要载于下文摘要。

selenium_ide_142

<2>Step 2-Nagate to the Results of Running Suite Tab and TestNG将显示以下结果摘要。

selenium_ide_141

Step 3——在生成超文本时,我们将能够以超文本格式看到测试结果。

selenium_ide_143
Advertisements