简体   繁体   English

如何使用相同的数据提供程序并行运行硒测试

[英]How to run selenium test in parallel using the same dataprovider

I have a scenario where i need to run my selenium test in parallel using the same data provider. 我有一种情况,我需要使用相同的数据提供程序并行运行我的硒测试。 From what i have read it is possible but could not get it to work.I have a hub and a node running on one machine and have another node running on another machine. 根据我的阅读,有可能但无法使其正常工作。我有一个集线器和一个节点在一台计算机上运行,​​而另一个节点在另一台计算机上运行。

My DataProvider 我的数据提供者

// Data provider for Storage Rule Suite
@DataProvider(name = "StorageRuleDataProvider", parallel =true)
public static Object[][] getStorageData(Method m) {
    return TestUtil.getData(m.getName(), TestBase.storageSuite);
}

My Test 我的测试

@Test(groups = { "CreateNewStorageRule" }, dependsOnGroups = { "StoragePage" }, dataProviderClass = TestDataProvider.class, dataProvider = "StorageRuleDataProvider", threadPoolSize = 20)
public void createNewStorageRuleTest(Hashtable<String, String> data){}

XML XML格式

<suite name="Storage Rule Suite" parallel="tests" data-provider-thread-count="20"  >

When i run the test in the xml file, i have two set of browser opening on each node but when it attempts to do a login, sometimes it enters the credentials twice in one browser and nothing on the other and sometimes nothing gets entered on one browser. 当我在xml文件中运行测试时,我在每个节点上都打开了两组浏览器,但是当它尝试进行登录时,有时会在一个浏览器中两次输入凭据,而在另一个浏览器中则什么都不输入,有时在一个浏览器中没有输入任何内容浏览器。

First, you have to use parallel="methods" to run your @Test methods in parallel. 首先,您必须使用parallel="methods"运行@Test方法。 Second: I had a similar problem, that more Test methods got executed in the same browser and I solved it by making my WebDriver ThreadSafe. 第二:我有一个类似的问题,更多的Test方法在同一浏览器中执行,我通过制作WebDriver ThreadSafe解决了它。

What you describe is a classical example of non-thread-safe Selenium test automation framework. 您所描述的是非线程安全的Selenium测试自动化框架的经典示例。 In most cases you solve this by having an instance of driver per test class, and running all tests from that class in single thread. 在大多数情况下,您可以通过每个测试类具有一个驱动程序实例,然后在单个线程中运行该类的所有测试来解决此问题。

However, if you want to run content of single test class in multiple parallel threads, you need to redesign is-a & has-a relationships in your framework. 但是,如果要在多个并行线程中运行单个测试类的内容,则需要在框架中重新设计is-a和has-a关系。 Here is a detailed example of how this can be done: 这是如何完成此操作的详细示例:

http://automatictester.co.uk/2015/04/11/parallel-execution-on-method-level-in-selenium-testng-framework http://automatictester.co.uk/2015/04/11/parallel-execution-on-method-level-in-selenium-testng-framework

Although, this may add extra work and additional compexity to your test automation. 虽然,这可能会给您的测试自动化增加额外的工作量和额外的兼容性。 I'd think twice why you want to run Selenium test methods using data provider in parallel and try to answer the question if you really need to do that. 我会三思而后行,为什么要并行使用数据提供程序运行Selenium测试方法,并尝试回答是否确实需要这样做的问题。

According to my experiences, if you start combining Data Providers with Selenium, you may have a problem with overall test approach. 根据我的经验,如果您开始将数据提供程序与Selenium结合使用,则可能会对整体测试方法产生疑问。 Perhaps you try to automate too much on UI level, instead of pushing the tests down the stack to eg API level. 也许您尝试在UI级别上实现太多自动化,而不是将测试向下推到例如API级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM