【问题标题】:Selenium grid parallel execution of test is opening browser in silent modeSelenium 网格并行执行测试正在以静默模式打开浏览器
【发布时间】:2020-09-22 14:18:42
【问题描述】:

我正在尝试使用网格基础架构运行 selenium 测试。

硒版本 - 3.141.59 TestNG 版本 - 7.3.0 硒远程驱动程序 - 3.141.5

我尝试了顺序执行和并行执行,在这两种情况下,测试都运行良好,但以静默模式打开(意味着在最小化窗口中)并且没有显示为活动窗口。

注意 - 我在一台 Windows 7 64 位计算机上同时运行集线器和节点。

这是我的测试用例:


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.



【问题讨论】:

    标签: java selenium grid testng


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-13
      • 2012-04-30
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多