gpt4 book ai didi

java - Selenium 测试未使用 testng 在网格中并行运行

转载 作者:行者123 更新时间:2023-11-30 11:16:41 25 4
gpt4 key购买 nike

注意:

在 testng xml 中,如果我将 parallel= 更改为类或方法,那么它可以正常运行测试,但它不是并行地一个一个地执行。

如果我保留 parallel="tests",那么它会并行运行,但它会在同一个虚拟机中打开同一个浏览器三次,这是不正确的。

我的设置:

我设置了 11 个虚拟机,并且已经为每个盒子上的每个浏览器初始化了 Selenium Grid 节点。我已经创建了我的 testng xml 来在每个盒子上运行测试。这些测试是使用 Webdriver 用 Ja​​va 编写的。

我的问题:

当我执行测试时,打开了 3 个 IE 实例,测试在同一个虚拟机中并行运行。我使用正确的节点设置了不同的 VM,因此根据下面的 testng xml,我希望测试能够在不同 VM 的 IE、FF 和 IE9 中正确运行。

TESTNG XML

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests" >

<tests>

<test name="IE11">

<parameter name="GridBrowser" value="iexplore11windows7"/>

<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>

<test name="FF25">

<parameter name="GridBrowser" value="firefox25win7"/>

<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>


<test name="IE9">

<parameter name="GridBrowser" value="iexplore9windows7"/>

<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>

</tests>

</suite>

CONFIGURATION.JAVA

package com.environments;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.openqa.selenium.remote.DesiredCapabilities;

public class Configuration {

public static DesiredCapabilities setCap;

public static String SeleniumGridSetup(String gridBrowser) {

String newGridBrowser = gridBrowser;

switch (newGridBrowser) {


// QA CLIENT 11

case "iexplore8windowsXP":

System.out.println("Internet Explorer 8 on Windows XP");
setCap= DesiredCapabilities.internetExplorer();
setCap.setBrowserName("internet explorer");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("8.0");
break;

case "firefox23":

System.out.println("Firefox 23 on Windows XP");
setCap= DesiredCapabilities.firefox();
setCap.setBrowserName("firefox");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("23.0");
break;

case "chromeLatestwinXP":

System.out.println("Chrome Latest Version on Windows XP");
setCap= DesiredCapabilities.chrome();
setCap.setBrowserName("chrome");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("L1");
break;

// QA CLIENT 10

case "iexplore7winXP":

System.out.println("Internet Explorer 7 on Windows XP");
setCap= DesiredCapabilities.internetExplorer();
setCap.setBrowserName("internet explorer");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("7.0");
break;


...... ETC ETC
}

return newGridBrowser;
}

测试类

package test.authentication;

import java.net.URL;

import static org.testng.Assert.fail;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import ui.common.masthead;
import ui.authentication.logInPage;

import com.environments.Configuration;
import com.thoughtworks.twist.core.execution.TwistScenarioDataStore;
import com.data.Users;

public class LoginWithCorrectUsernameToTESConnect {

public WebDriver browser;
public static String url;
private StringBuffer verificationErrors = new StringBuffer();

@Autowired
private TwistScenarioDataStore scenarioStore;


// Selenium grid constructor for running tests in the Grid

@Parameters({"GridBrowser"})
public LoginWithCorrectUsernameToTESConnect(String GridBrowser) throws Exception {

Configuration.SeleniumGridSetup(GridBrowser);
browser = new RemoteWebDriver(new URL(Configuration.getHubUrl()), Configuration.setCap);

url = Configuration.getUrl();
browser.manage().window().maximize();
browser.navigate().to(url);
}

// Webdriver constructor for running tests using the Twist IDE

public LoginWithCorrectUsernameToTESConnect(WebDriver browser) throws Exception {

this.browser = browser;
browser.manage().window().maximize();

url = Configuration.getUrl();
browser.navigate().to(url);
}

// Test method for login to TES Connect start from here

@Test
public void loginWithDifferentUsersAndVerifyUsernameDisplayed() throws Exception {

for (int i = 0; i < Users.getUsernameFromList().size(); i++) {

try {

browser.findElement(masthead.UCP.loginLink).click();
browser.findElement(logInPage.usernameInput).sendKeys(Users.getUsernameFromList().get(i));
browser.findElement(logInPage.passwordInput).sendKeys(Configuration.getGenericUserPassword());
browser.findElement(logInPage.logInButton).click();

Assert.assertEquals(browser.findElement(masthead.UCP.userName).getText(), Users.getUsernameFromList().get(i), "Username did not match");
browser.findElement(masthead.UCP.logoutLink).click();

}
catch (Error e) {

verificationErrors.append(e.toString());
}
}
}

@AfterTest
public void tearDown() {

browser.quit();

String verificationErrorString = verificationErrors.toString();

if (!"".equals(verificationErrorString)) {

fail(verificationErrorString);
}
}
}

最佳答案

在将以下内容添加到我的 selenium 节点后,我现在已经设法让它工作了:

最大实例数=5最大 session =5

关于java - Selenium 测试未使用 testng 在网格中并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24755904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com