Проблема (Вопрос) заключается в том, что автотест корректно отрабатывает только с первым элементом массива, который лежит в DataProvider. со всеми остальными автотест падает с ошибкой “org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?”
Я попытался поменять afterMethod. Вместо driver.quit писал driver.close
Мой pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>allureTestNGExample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.plugin.validation>DEFAULT</maven.plugin.validation>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- Compiler plug-in -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.12.0</version>
</plugin>
<!-- Added Surefire Plugin configuration to execute tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.6/aspectjweaver-1.9.6.jar"
</argLine>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.17.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.3</version>
</dependency>
</dependencies>
</project>
Код абстрактного класса, от которого наследуются все тесты:
code
public abstract class BaseTest {
private WebDriverWait wait2;
private WebDriverWait wait5;
private WebDriver driver;
private static final String BASE_URL = "https://www.saucedemo.com/";
@BeforeMethod(description = "Browser startUp")
protected void beforeMethod() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*", /*"--headless",*/ "--window-size=1920,1080");
driver = new ChromeDriver(chromeOptions);
driver.manage().window().maximize();
getDriver().get(BASE_URL);
}
@AfterMethod(description = "Browser tearDown")
protected void afterMethod() {
if (driver != null) {
driver.quit();
}
}
protected WebDriver getDriver() {
return driver;
}
protected WebDriverWait getWait2() {
if (wait2 == null) {
wait2 = new WebDriverWait(getDriver(), Duration.ofSeconds(2));
}
return wait2;
}
Сам тест:
public class ExperimenthalTest extends BaseTest {
@DataProvider
public Object [][] data () {
return new Object[][]{
{""},
{"a"},
{"al"},
{"ale"},
{"aaaaaaaaaaaaalex"},
{"aaaaaaaaaaaaaalex"},
{"aaaaaaaaaaaaaaalex"},
{"alex!"},
{"alex@"},
{"alex#"},
{"alex$"},
{"alex%"}
};
}
@Epic(value = "Проверки полей")
@Feature(value = "Данные покупателя")
@Story(value = "Проверки полей страницы заполнения данных юзера")
@Severity(value = SeverityLevel.NORMAL)
@Description(value = "Проверка поля NAME на граничные значения и спецсимволы ....")
@Test(dataProvider = "data")
public void theFirstDataProviderTest(String s) throws InterruptedException {
WebElement loginField = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='user-name']")));
WebElement passField = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='password']")));
WebElement submitButton = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='login-button']")));
loginField.sendKeys("standard_user");
passField.sendKeys("secret_sauce");
submitButton.click();
Thread.sleep(1000);
WebElement backPackTitle = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[contains(@class,'inventory_item_name')][contains(text(),'Sauce Labs Backpack')]")));
backPackTitle.click();
Thread.sleep(1000);
WebElement addBackPackToCart = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@data-test='add-to-cart-sauce-labs-backpack']")));
addBackPackToCart.click();
Thread.sleep(1000);
WebElement backPackCartIcon = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='shopping_cart_link']")));
backPackCartIcon.click();
Thread.sleep(1000);
WebElement chekoutButton = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@data-test='checkout']")));
chekoutButton.click();
final String buyersInfoPageTitle = getWait5().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"header_container\"]/div[2]/span"))).getText();
Assert.assertEquals(buyersInfoPageTitle, "Checkout: Your Information");
WebElement firstNameField = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='First Name']")));
firstNameField.sendKeys(s);
WebElement lastNameField = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='Last Name']")));
lastNameField.sendKeys("Harris");
WebElement postCodeField = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@placeholder='Zip/Postal Code']")));
postCodeField.sendKeys("123456");
WebElement submitButtonCheckout = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='submit']")));
submitButtonCheckout.click();
String checkoutTitle = getWait2().until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@class='title'][contains(text(),'Checkout: Overview')]"))).getText();
Assert.assertEquals(checkoutTitle,"Checkout: Overview");
}
Ошибка вот такая
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.5'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, findElement {using=xpath, value=//*[@id='user-name']}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 119.0.6045.105, chrome: {chromedriverVersion: 119.0.6045.105