现在我有 80 个使用数据提供程序的测试方法 (@Test) 我正在运行我的测试用例及其近 400 个测试用例。当我在硒网格中并行运行它时,它只运行几个测试用例。有时 40 有时 50 随机运行 这是我的基类
public class BaseTest {
private static final String OS = System.getProperty("os.name").toLowerCase();
public static boolean IS_WINDOWS = (OS.indexOf("win") >= 0);
public WebDriver driver;
String report = null;
public WebDriver getDriver() {
return driver;
}
@BeforeClass(alwaysRun = true)
public void classLevelSetup() throws InterruptedException {
//Did nothing
}
@BeforeMethod(alwaysRun = true)
public void methodLevelSetup() throws ParseException, MalformedURLException {
Log.info("Tests are starting!");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--disable-extensions");
chromeOptions.addArguments("disable-infobars");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("ignore-certificate-errors");
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
chromeOptions.addArguments("--start-maximized");
driver=new RemoteWebDriver(new
URL("http://localhost:4444/wd/hub"),chromeOptions);
// Added Browser
}
@AfterMethod(alwaysRun = true)
public void AfterMethod(ITestResult result, ITestContext ctx)
{
getTest().fail(result.getThrowable());
driver.quit();
}
@AfterClass(alwaysRun = true)
public void teardown() {
//Did nothing
}
这是我的测试课
public class DashboardTest extends BaseTest {
@DataProvider(name = "CreateProperty")
public Object[][] getData() {
Object[][] data = SiteConfig.CreateProperty;
return data;
}
@Test(priority = 0, alwaysRun = true, dataProvider = "CreateProperty", description = "Add new property from Management > Properties")
public void Add_new_Property_from_management_Properties(String url, String username, String password, Method method, ITestContext ctx) throws Exception {
SignupPage sp = new SignupPage(driver);
sp.Open_login_Page(url);
}
}
这是我的 testng.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<test name="CultBooking">
<classes>
<class name="tests.RoomTypeTest"></class>
<class name="tests.RoomTypeTest_1"></class>
<class name="tests.RoomTypeTest_2"></class>
<class name="tests.RoomTypeTest_3"></class>
<class name="tests.RoomValidatyApiResponseTest"></class>
<class name="tests.MealPlanTest"></class>
<class name="tests.MealPlanTest_1"></class>
<class name="tests.MasterdataTest"></class>
<class name="tests.DescriptionsTest"></class>
<class name="tests.SignupTest"></class>
<class name="tests.Reservation_processTest"></class>
<class name="tests.SignInTest"></class>
<class name="tests.DashboardTest"></class>
<class name="tests.ForgotPasswordTest"></class>
</classes>
</test>
**我在 jenkins 中运行所有内容,这是我有时遇到的错误**
Command: [54f8c566912260f004c50d969fb3fbb8, screenshot {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome,
browserVersion: 96.0.4664.45, chrome: {chromedriverVersion:
96.0.4664.45 (76e4c1bb2ab46..., userDataDir: /tmp/.com.google.Chrome.DIPhAl}, goog:chromeOptions: {debuggerAddress:
localhost:36179}, javascriptEnabled: true, networkConnectionEnabled:
false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX,
proxy: Proxy(), se:cdp: ws://172.19.0.4:4444/sessio..., se:cdpVersion:
96.0.4664.45, se:vnc: ws://172.19.0.4:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.19.0.4:7900, setWindowRect: true,
strictFileInteractability: false, timeouts: {implicit: 0, pageLoad:
300000, script: 30000}, unhandledPromptBehavior: dismiss and notify,
webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true,
webauthn:virtualAuthenticators: true} Session ID:
54f8c566912260f004c50d969fb3fbb8 at
jdk.internal.reflect.GeneratedConstructorAccessor27.newInstance(Unknown
Source) at
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at
org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at
org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:50)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:614)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
at
org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:349)
at
utils.listeners.TestListener.saveScreenshotPNG(TestListener.java:39)
at utils.listeners.TestListener.onTestFailure(TestListener.java:78)
at
org.testng.internal.TestListenerHelper.runTestListeners(TestListenerHelper.java:96)
at
org.testng.internal.TestInvoker.runTestResultListener(TestInvoker.java:219)
at
org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:834)
at
org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
谁能帮我解决这个问题?