简体   繁体   中英

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

I am trying to run selenium tests using grid infrastructure.

Selenium version - 3.141.59 TestNG version - 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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