【问题标题】:Parllel execution with in @Test annotations使用 @Test 注释并行执行
【发布时间】:2018-07-26 17:05:57
【问题描述】:

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

@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(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

<?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

【问题讨论】:

  • 在数据提供中尝试一次没有parallel = true,如果它工作正常,那么我们需要进一步研究。
  • 我添加了我得到的错误。我尝试删除 parallel = test 这使得测试以 1 比 1 运行,但不是并行的。请检查我上面得到的错误。

标签: selenium testng dataprovider


【解决方案1】:

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

For reference read this document

【讨论】:

  • 我已经更新了我得到的错误问题,看看。
猜你喜欢
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多