Я использую POM от Selenium Java. При попытке запустить два класса параллельно с помощью TestNG xml я столкнулся с проблемой: второй класс не работает должным образом. Но когда я использую аннотацию @BeforeClass, то с двумя разными окнами второй класс работает отлично.
Все мои классы страниц объектной модели страницы и тестовые классы приведены ниже
Базовая страница:
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class BasePage {
WebDriver driver;
WebDriverWait wait;
public BasePage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
PageFactory.initElements(driver, this);
}
}
Страница входа:
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class LoginPage extends BasePage{
public LoginPage(WebDriver driver) {
super(driver);
}
// sign in button locator
@FindBy(css = ".login-btn")
WebElement SetSignInBtn;
// email locator
@FindBy(xpath = "//div[@class='form-group label-up']//input[@type='text']")
WebElement SetEmailField;
// proceed btn locator
@FindBy(css = ".form-group.text-center")
WebElement SetProceedBtn;
// password locator
@FindBy(css = "input[type='password']")
WebElement SetPass;
// sign in button locator
@FindBy(id = "sign_in_button")
WebElement SignBtn;
public void Login(String mail, String passWord){
// sign in button click
SetSignInBtn.click();
// email field input
wait.until(ExpectedConditions.visibilityOf(SetEmailField));
SetEmailField.sendKeys(mail);
// proceed button click
SetProceedBtn.click();
// pass field input
wait.until(ExpectedConditions.visibilityOf(SetPass));
SetPass.sendKeys(passWord);
SignBtn.click();
}
}
Страница пополнения счета:
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import java.beans.Visibility;
public class RechargePage extends BasePage{
public RechargePage(WebDriver driver) {
super(driver);
}
@FindBy(id = "typeahead-basic")
WebElement mobileNumberField;
@FindBy(id = "telecom-operator")
WebElement selectOperator;
@FindBy(id = "connection-type")
WebElement connectionType;
@FindBy(xpath = "//input[@formcontrolname='amount']")
WebElement amount;
@FindBy(css = "button[type='submit']")
WebElement proceedBtn;
public void recharge(String mobileNumber, String rechargeAmount){
mobileNumberField.sendKeys(mobileNumber);
wait.until(ExpectedConditions.visibilityOf(selectOperator));
selectOperator.click();
WebElement operatorDropdown = driver.findElement(By.id("telecom-operator"));
Select dropDownOperator = new Select(operatorDropdown);
dropDownOperator.selectByIndex(5);
//dropDownOperator.getFirstSelectedOption().click();
wait.until(ExpectedConditions.visibilityOf(connectionType));
connectionType.click();
WebElement connectionDropdown = driver.findElement(By.id("connection-type"));
Select dropDownConnection = new Select(connectionDropdown);
dropDownConnection.selectByIndex(1);
amount.sendKeys(rechargeAmount);
wait.until(ExpectedConditions.visibilityOf(proceedBtn));
proceedBtn.click();
}
}
Базовый тест:
package pages;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.*;
import java.util.concurrent.TimeUnit;
public class BaseTest {
WebDriver driver;
@BeforeSuite
public void setup(){
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https:");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@AfterSuite
public void tearDown() throws InterruptedException {
Thread.sleep(5000);
driver.close();
}
}
Проверка входа:
package pages;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest{
@Test(priority = 1)
public void testLogin() throws InterruptedException {
LoginPage loginPage = new LoginPage(driver);
loginPage.Login("01791557029", "123456");
Thread.sleep(5000);
}
}
Тест перезарядки:
package pages;
import org.testng.annotations.Test;
public class RechargeTest extends BaseTest{
@Test(priority = 2)
public void testRecharge(){
RechargePage rechargePage = new RechargePage(driver);
rechargePage.recharge("01687663220", "100");
}
}
А вот мой XML-файл TestNG:
Подробнее здесь: https://stackoverflow.com/questions/792 ... es-error-b
Когда я пытаюсь запустить два класса параллельно в TestNG xml, второй класс выдает ошибку. Но работает, если оба класса ⇐ JAVA
Программисты JAVA общаются здесь
1732715279
Anonymous
Я использую POM от Selenium Java. При попытке запустить два класса параллельно с помощью TestNG xml я столкнулся с проблемой: второй класс не работает должным образом. Но когда я использую аннотацию @BeforeClass, то с двумя разными окнами второй класс работает отлично.
Все мои классы страниц объектной модели страницы и тестовые классы приведены ниже
Базовая страница:
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class BasePage {
WebDriver driver;
WebDriverWait wait;
public BasePage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
PageFactory.initElements(driver, this);
}
}
Страница входа:
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class LoginPage extends BasePage{
public LoginPage(WebDriver driver) {
super(driver);
}
// sign in button locator
@FindBy(css = ".login-btn")
WebElement SetSignInBtn;
// email locator
@FindBy(xpath = "//div[@class='form-group label-up']//input[@type='text']")
WebElement SetEmailField;
// proceed btn locator
@FindBy(css = ".form-group.text-center")
WebElement SetProceedBtn;
// password locator
@FindBy(css = "input[type='password']")
WebElement SetPass;
// sign in button locator
@FindBy(id = "sign_in_button")
WebElement SignBtn;
public void Login(String mail, String passWord){
// sign in button click
SetSignInBtn.click();
// email field input
wait.until(ExpectedConditions.visibilityOf(SetEmailField));
SetEmailField.sendKeys(mail);
// proceed button click
SetProceedBtn.click();
// pass field input
wait.until(ExpectedConditions.visibilityOf(SetPass));
SetPass.sendKeys(passWord);
SignBtn.click();
}
}
Страница пополнения счета:
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import java.beans.Visibility;
public class RechargePage extends BasePage{
public RechargePage(WebDriver driver) {
super(driver);
}
@FindBy(id = "typeahead-basic")
WebElement mobileNumberField;
@FindBy(id = "telecom-operator")
WebElement selectOperator;
@FindBy(id = "connection-type")
WebElement connectionType;
@FindBy(xpath = "//input[@formcontrolname='amount']")
WebElement amount;
@FindBy(css = "button[type='submit']")
WebElement proceedBtn;
public void recharge(String mobileNumber, String rechargeAmount){
mobileNumberField.sendKeys(mobileNumber);
wait.until(ExpectedConditions.visibilityOf(selectOperator));
selectOperator.click();
WebElement operatorDropdown = driver.findElement(By.id("telecom-operator"));
Select dropDownOperator = new Select(operatorDropdown);
dropDownOperator.selectByIndex(5);
//dropDownOperator.getFirstSelectedOption().click();
wait.until(ExpectedConditions.visibilityOf(connectionType));
connectionType.click();
WebElement connectionDropdown = driver.findElement(By.id("connection-type"));
Select dropDownConnection = new Select(connectionDropdown);
dropDownConnection.selectByIndex(1);
amount.sendKeys(rechargeAmount);
wait.until(ExpectedConditions.visibilityOf(proceedBtn));
proceedBtn.click();
}
}
Базовый тест:
package pages;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.*;
import java.util.concurrent.TimeUnit;
public class BaseTest {
WebDriver driver;
@BeforeSuite
public void setup(){
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https:");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@AfterSuite
public void tearDown() throws InterruptedException {
Thread.sleep(5000);
driver.close();
}
}
Проверка входа:
package pages;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest{
@Test(priority = 1)
public void testLogin() throws InterruptedException {
LoginPage loginPage = new LoginPage(driver);
loginPage.Login("01791557029", "123456");
Thread.sleep(5000);
}
}
Тест перезарядки:
package pages;
import org.testng.annotations.Test;
public class RechargeTest extends BaseTest{
@Test(priority = 2)
public void testRecharge(){
RechargePage rechargePage = new RechargePage(driver);
rechargePage.recharge("01687663220", "100");
}
}
А вот мой XML-файл TestNG:
Подробнее здесь: [url]https://stackoverflow.com/questions/79224122/when-i-try-to-run-two-classes-parallelly-in-testng-xml-2nd-class-gives-error-b[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия