selenium 项目的批处理文件创建

Batch File creation for selenium project

我需要创建一个 .bat 文件来执行我用 TestNG 创建的 selenium 项目。 我创建了 .xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testing 07ZR" parallel="methods" thread-count="2">
    <test name="Automation">
         <classes>
             <class name="AjouterPanier.AjoutPanier"/>
          </classes>
     </test> <!-- Test -->
</suite> <!-- Suite -->

问题是我有两个@Test,由于某种原因,他好像在同一时间执行它们,因为当他尝试登录时,他输入了两次登录值。 作为参考,这是我的 .bat 文件:

set projectLocation="Project Path"
cd %projectLocation%
set classpath=%projectLocation%\bin;%projectLocation%\lib\*
java org.testng.TestNG %projectLocation%\testng.xml
pause

有人能告诉我我需要做什么才能让两个@Test 一个接一个地执行吗?

parallel="methods" thread-count="2" 您正在 parallel 线程中请求 TestNG 到 运行 每个 Method,使用 2 个线程池。因此,这可以解释 ABCABC

需要考虑的几点:

<suite> 标签上的 parallel 属性可以采用以下值之一:

<suite name="My suite" parallel="methods" thread-count="5">
<suite name="My suite" parallel="tests" thread-count="5">
<suite name="My suite" parallel="classes" thread-count="5">
<suite name="My suite" parallel="instances" thread-count="5">


parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.

parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.

parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.

parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.

在你的情况下,因为你的方法似乎不是线程安全的,我建议你使用 thread-count="1",或者简单地查看上面的选项,看看什么最适合你,如果你真的很想 运行 进入 parallel 模式。

<suite name="Testing 07ZR" parallel="methods" thread-count="1">

或非并行模式:

<suite name="Testing 07ZR">

如果您希望同一个 TestClass 中的方法按特定顺序 运行,您还可以使用 priority:

priority The priority for this test method. Lower priorities will be scheduled first.

示例:

@Test(priority=1)
public void Test1() {

}

@Test(priority=2)
public void Test2() {

}

@Test(priority=3)
public void Test3() {

}

然后他们会运行,依次为Test1、Test2、Test3。

https://testng.org/doc/documentation-main.html#test-groups