Selenium Grid将值并行发送到一个浏览器

问题描述 投票:2回答:2

我正在尝试并行运行硒,但遇到一些重大问题。我遇到的一个主要问题是,WebDriver将所有值发送到一个浏览器,然后再次运行它将首先运行以进行测试,然后进行第二次测试,它将不发送任何值,然后另一个测试可能会在打开时挂起。我见过人们可以使其在YouTube上完美运行,甚至以为我已经尝试了一切,但我认为它从来没有像现在这样成功过。我知道端口可以作为参数传递,我以前有过,但是我认为它不是必需的。

这是从集线器/节点设置开始的所有设置步骤...

java -jar selenium-server-standalone-2.47.1.jar -role hub-maxInstances = 10 -maxSession = 10-端口7777-超时29000

java -jar selenium-server-standalone-2.47.1.jar -role Webdriver -hubhttp://localhost:7777/grid/register-maxSession = 5 -maxInstance = 5-port 4441 -timeout 30000-浏览器browserName =“ safari”,platform = WINDOWS

java -jar selenium-server-standalone-2.45.0.jar -role Webdriver -hubhttp://localhost:7777/grid/register-端口4448-超时30000-浏览器browserName =“ firefox”,platform = WINDOWS,maxSession = 5,maxInstances = 5

我的xml文件

<?xml version="1.0" encoding="UTF-8"?>

<suite name = "Cross Browser Testing" verbose = "3" parallel = "tests" thread-count="5">
    <test name = "Firefox Test">
    <parameter name = "browser" value ="firefox">
    </parameter>
        <classes>
            <class name = "TestClass.Dashboard"/>
            <class name = "TestClass.Login"/>           
        </classes>
    </test> 

        <test name = "Safari Test">
    <parameter name = "browser" value ="safari">
    </parameter>
        <classes>
            <class name = "TestClass.Dashboard"/>
            <class name = "TestClass.Login"/>           
        </classes>
    </test>     
</suite>

这是我如何调用xml

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

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.*;

public class Launch extends AbstractPage {

    public Launch() {
        super();
    }   

    @BeforeMethod
    @Parameters({"browser"})
    public void launchBrowsers(String browser) throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setBrowserName(browser);
        capabilities.setJavascriptEnabled(true);

        // To remove message "You are using an unsupported command-line
        // flag: --ignore-certificate-errors.
        // Stability and security will suffer."
        // Add an argument 'test-type'
        ChromeOptions chrome = new ChromeOptions();
        chrome.addArguments("test-type");
        capabilities.setCapability(ChromeOptions.CAPABILITY, chrome);
        capabilities.setCapability("chrome.binary",
                "C:\\location\\chromedriver.exe");

        //setup internet explorer
        capabilities.setCapability("InternetExplorerDriverServer.IE_ENSURE_CLEAN_SESSION",true);
        System.setProperty("webdriver.ie.driver",
                "C:\\location\\IEDriverServer.exe");

        selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities);

        getSelenium().manage().window().maximize();
        getSelenium().manage().deleteAllCookies();

    }   

    @AfterMethod
    public void tearDown() {
        //close down browser window
        if (selenium == null) {
            try {
                selenium.quit();
                selenium.close();
            } catch (Exception e) {

            }
        }
    }
}

我也尝试过switch语句

switch(browser) {

        case "iexplorer":   
            System.setProperty("webdriver.ie.driver",
                    "C:\\location\\IEDriverServer.exe");
            DesiredCapabilities capabilities1 = DesiredCapabilities.internetExplorer();             
            selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities1); 
            break;

        case "firefox":
            DesiredCapabilities capabilities2 = DesiredCapabilities.firefox();              
            selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities2); 
            break;  

        case "safari":
            DesiredCapabilities capabilities3 = DesiredCapabilities.safari();               
            selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities3); 
            break;  

        case "chrome":
            System.setProperty("chrome.binary",
                    "C:\\location\\chromedriver.exe");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();                
            selenium = new RemoteWebDriver(new URL("http://localhost:7777/wd/hub"), capabilities);          
            break;  

        default:
            break;
    }

非常感谢您提供帮助,以使其能够正常工作。

java selenium-webdriver testng selenium-grid
2个回答
0
投票

这里是链接Selenium Grid,用于使用网格设置和执行硒测试套件。

我之前一直遵循并成功执行。


0
投票

我也有同样的问题。我还在一个节点上并行运行两个浏览器,但是无论哪个浏览器首先启动,它都会尝试仅在该浏览器中执行所有操作,而在第二个浏览器中,它则不执行任何操作(即使未将URL传递给它)。正如我所做的是,在代码中webdriver设置为静态导致了所有问题,因此我从我的webdriver中删除了静态]]并进行了尝试,然后工作正常。您只需尝试将其声明为public并尝试一下即可。可能有效。

© www.soinside.com 2019 - 2024. All rights reserved.