与 @Test 注释并行执行 [英] Parllel execution with in @Test annotations

查看:22
本文介绍了与 @Test 注释并行执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在从 Webdriver.get(urls) 打开的多个实例上执行操作(切换到框架、NavigateToAgents 和 writeToExcel).现在它只在打开的浏览器的第一个实例上运行其余的操作(切换到框架、NavigateToAgents 和 writeToExcel),但不在其他浏览器上.

I want the actions(switch to frame, NavigateToAgents and writeToExcel) to be performed on multiple instances that open from Webdriver.get(urls). for now it just runs rest of the actions(switch to frame, NavigateToAgents and writeToExcel) on 1st instance of browser that is opened but not on others.

@Test(dataProvider = "data")
public static void stopAgents(String urls) throws Exception {

    setup();    //Setup of browser

    WebDriver.get(urls); // opening multiple instances of webdriver from list of urls from dataprovider

    switchToLeftFrame();

    navigateToAgents();

    writeToExcel(sheetName, methodType); //i want to write to excel the tables of both the instances which are opened

//dataprovider 传递 url 列表

//dataprovider passes list of urls

   @DataProvider(name = "data", parallel = true)
    public Object[][] data() {

    Configuration configuration = Configuration.getConfiguration();

    List<String> urls = configuration.getListOfUrls();

    Object[][] data = new Object[urls.size()][1];

    for (int i = 0; i < data.length; i++) {
        data[i][0] = urls.get(i);
    }

    return data;
}

//TestNG XML

// TestNG XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite" data-provider-thread-count="2">
<test thread-count="5" name="Test">
<classes>
  <class name="testng.data.StopAgents"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

运行上面的代码时出错

org.openqa.selenium.json.JsonException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'LH7U05CG7370KZ5', ip: '10.195.232.34', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:172)
    at org.openqa.selenium.json.JsonInput.beginObject(JsonInput.java:103)
    at org.openqa.selenium.json.MapCoercer.lambda$apply$1(MapCoercer.java:64)
    at org.openqa.selenium.json.MapCoercer$$Lambda$105/1929913939.apply(Unknown Source)
    at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:142)
    at org.openqa.selenium.json.JsonTypeCoercer$$Lambda$109/1456010139.apply(Unknown Source)
    at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:122)
    at org.openqa.selenium.json.Json.toType(Json.java:62)
    at org.openqa.selenium.json.Json.toType(Json.java:52)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:87)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:828)
    at testng.data.MethodsProgress.setup(MethodsProgress.java:450)
    at testng.data.parllel.stopAgents(parllel.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:73)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:14)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
    at org.openqa.selenium.json.JsonInput$$Lambda$93/585885412.execute(Unknown Source)
    at org.openqa.selenium.json.JsonInput$VoidCallable.call(JsonInput.java:181)
    at org.openqa.selenium.json.JsonInput$VoidCallable.call(JsonInput.java:176)
    at org.openqa.selenium.json.JsonInput.execute(JsonInput.java:168)
    ... 32 more

推荐答案

您需要在 XML 文件中传递 parallel="tests".

You need to pass parallel="tests" in your XML file.

参考阅读本文档

这篇关于与 @Test 注释并行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆