Создание пакетного файла для проекта selenium

#java #selenium #testng

Вопрос:

Мне нужно создать файл .bat для выполнения моего проекта selenium, который я создал с помощью TestNG. Я создал файл .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 выполнялись один за другим?

Комментарии:

1. Какую ошибку вы получаете?

2. это не ошибка, как я уже сказал, это больше похоже, например, если логин «ABC» в моем вводе я нахожу «ABCABC»

Ответ №1:

parallel="methods" thread-count="2" Вы запрашиваете TestNG запустить каждый Method из них в потоках, в parallel , используя пул из 2 потоков. Поэтому это может объяснить ABCABC

Несколько вещей, которые следует учитывать:

parallel Атрибут в <suite> теге может принимать одно из следующих значений:

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

Если вы хотите, чтобы ваши методы внутри одного и того же тестового класса выполнялись в определенном порядке, вы также можете использовать priority :

приоритет Приоритет для данного метода тестирования. Сначала будут запланированы более низкие приоритеты.

Пример:

 @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