简体   繁体   English

Selenium 网格并行执行测试以静默模式打开浏览器

[英]Selenium grid parallel execution of test is opening browser in silent mode

I am trying to run selenium tests using grid infrastructure.我正在尝试使用网格基础设施运行 selenium 测试。

Selenium version - 3.141.59 TestNG version - 7.3.0 selenium-remote-driver - 3.141.5 Selenium 版本 - 3.141.59 TestNG 版本 - 7.3.0 selenium-remote-driver - 3.141.5

I tried both sequential and parallel execution, and in both the cases, the tests are running fine, but opening in silent mode (means in minimized window) and not shown as active window.我尝试了顺序和并行执行,在这两种情况下,测试都运行良好,但以静默模式打开(意味着在最小化窗口中)并且未显示为活动窗口。

Note - I am running both hub and node in a single Windows 7 64 bit computer.注意 - 我在一台 Windows 7 64 位计算机上同时运行集线器和节点。

Here is my test case :这是我的测试用例:


import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class GridExample1 {
    
    @Test
    @Parameters("browserType")
    
    public void getUrl1(String browserType) throws MalformedURLException
    {
        
        DesiredCapabilities cap = null;
        if(browserType.equals("FF")) {
        cap= DesiredCapabilities.firefox();
        cap.setBrowserName("firefox");
        }
        if(browserType.equals("Chrome")) {
            cap= DesiredCapabilities.chrome();
            cap.setBrowserName("chrome");
            }
        cap.setPlatform(Platform.WINDOWS);
        RemoteWebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.4:4444/wd/hub"),cap);
        driver.get("https://www.google.com");
        driver.findElement(By.name("q")).sendKeys("Grid");
        //driver.quit();
    }
    
    

}```

And my testng.xml -

 

    ```<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="GridDemo" parallel="classes" thread-count="2">
      <test name="GridTestSerialExecChrome">
      <parameter name="browserType" value="Chrome"></parameter>
        <classes>
          <class name="tests.GridExample1"/>
        </classes>
      </test> <!-- Test -->
      
      <test name="GridTestSerialExecFF">
      <parameter name="browserType" value="FF"></parameter>
        <classes>
          <class name="tests.GridExample1"/>
        </classes>
      </test> <!-- Test -->
    </suite> <!-- GridDemo -->```

pom.xml- 


    ```<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.grid.example</groupId>
      <artifactId>GridDemoTest</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <properties>
    
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.source>1.8</maven.compiler.source>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
    
        <dependencies>
            <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.141.59</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.testng/testng -->
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>7.3.0</version>
    
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-remote-driver</artifactId>
                <version>3.141.5</version>
            </dependency>
    
        </dependencies>
    </project>```

    Any idea if this is proper behavior of Selenium Grid/because I am running hub and node from same machine/anything wrong in the implementation?
    
    Please help.



在远程默认屏幕尺寸会很小,尝试通过以下选项

chrome_options.add_argument("--window-size=1920,1080")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM