Reputation: 1
when I start my whole test suite it works well till tests with @DataProvider start executing. Especially when Asserts crash. The suite stops executing and don't go to the next test.
Here's the text from the console:
There was an error in the forked process class Test.ExperimenthalTest cannot be cast to class Base.BaseTest (Test.ExperimenthalTest and Base.BaseTest are in unnamed module of loader 'app')
My 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.24.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.2</version>
</dependency>
</dependencies>
</project>
My testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
<listeners>
<listener class-name="io.qameta.allure.testng.AllureTestNg"/>
<listener class-name="Base.TestListener"/>
</listeners>
<test name="E2E">
<classes>
<class name="TestE2E.BuyBackPackTest">
<methods>
<include name="buyBackPack"/>
<include name="buyBackPack2"/>
</methods>
</class>
</classes>
</test>
<test name="MainPageGoodsTests">
<classes>
<class name="Test.AllGoodsPageTest">
<methods>
<include name="bikeLightHeaderTextTest"/>
<include name="backPackHeaderTextTest"/>
<include name="boltTshirtHeaderTextTest"/>
<include name="fleeceJacketHeaderTextTest"/>
<include name="whiteShirtHeaderTextTest"/>
<include name="hoodyHeaderTextTest"/>
</methods>
</class>
</classes>
</test>
<test name="MainPageEveryGoodTests">
<classes>
<class name="Test.EveryGoodTest">
<methods>
<include name="bikeLightPageTextTest"/>
<include name="backPackPageTextTest"/>
<include name="boltShirtPageTextTest"/>
<include name="fleeceJacketPageTextTest"/>
<include name="whiteShirtPageTextTest"/>
<include name="hoodyPageTextTest"/>
</methods>
</class>
</classes>
</test>
<test name="DataProviderTests">
<classes>
<class name="Test.ExperimenthalTest">
<methods>
<include name="theFirstDataProviderTest"/>
<include name="theFirstDataProviderTest2"/>
<include name="theFirstDataProviderTest3"/>
</methods>
</class>
</classes>
</test>
<test name="LoginTests">
<classes>
<class name="Test.LoginPageTest">
<methods>
<include name="enterTest"/>
<include name="enter2Test"/>
<include name="autorize2Test"/>
</methods>
</class>
</classes>
</test>
<test name="OtherTests">
<classes>
<class name="Test.ProviderResolveTest">
<methods>
<include name="theFirstDataProviderTest2"/>
</methods>
</class>
</classes>
</test>
</suite>
My Base class:
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() {
driver.quit();
}
protected WebDriver getDriver() {
return driver;
}
protected WebDriverWait getWait2() {
if (wait2 == null) {
wait2 = new WebDriverWait(getDriver(), Duration.ofSeconds(2));
}
return wait2;
}
protected WebDriverWait getWait5() {
if (wait5 == null) {
wait5 = new WebDriverWait(getDriver(), Duration.ofSeconds(5));
}
return wait5;
}
}
My testListener:
public class TestListener extends TestListenerAdapter {
@Override
public void onTestFailure(ITestResult result) {
Object currentClass = result.getInstance();
WebDriver driver = ((BaseTest) currentClass).getDriver();
takeScreenshot(driver, result.getName());
saveScreenshotToAllure(result.getName());
}
private void saveScreenshotToAllure(String screenshotName) {
try {
File screenshot = new File("./screenshots/" + screenshotName + ".png");
if (screenshot.exists()) {
byte[] screenshotContent = Files.readAllBytes(screenshot.toPath());
Allure.getLifecycle().addAttachment(screenshotName, "image/png", ".png", screenshotContent);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void takeScreenshot(WebDriver driver, String screenshotName) {
try {
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("./screenshots/" + screenshotName + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
My tests with @DataProvider:
@DataProvider(name = "data2")
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 = "Проверка поля LASTNAME на граничные значения и спецсимволы ....")
@Test(dataProvider = "data2", description = "Проверка поля LASTNAME")
public void theFirstDataProviderTest2(String option) throws IOException {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.saucedemo.com/");
WebElement loginField = driver.findElement(By.xpath("//*[@id='user-name']"));
WebElement passField = driver.findElement(By.xpath("//*[@id='password']"));
WebElement submitButton = driver.findElement(By.xpath("//*[@id='login-button']"));
Allure.step("Autorization");
loginField.sendKeys("standard_user");
passField.sendKeys("secret_sauce");
submitButton.click();
Allure.step("Going to the backpack's page");
WebElement backPackTitle = driver.findElement(By.xpath("//div[contains(@class,'inventory_item_name')][contains(text(),'Sauce Labs Backpack')]"));
backPackTitle.click();
Allure.step("Adding the backpack to the cart");
WebElement addBackPackToCart = driver.findElement(By.xpath("//button[@data-test='add-to-cart-sauce-labs-backpack']"));
addBackPackToCart.click();
Allure.step("Going to the cart");
WebElement backPackCartIcon = driver.findElement(By.xpath("//a[@class='shopping_cart_link']"));
backPackCartIcon.click();
Allure.step("Going to the checkout page");
WebElement chekoutButton = driver.findElement(By.xpath("//button[@data-test='checkout']"));
chekoutButton.click();
final String buyersInfoPageTitle = driver.findElement(By.xpath("//*[@id=\"header_container\"]/div[2]/span")).getText();
Allure.step("Checking that the checkout info page is existed");
Assert.assertEquals(buyersInfoPageTitle, "Checkout: Your Information");
Allure.step("Filling the field NAME");
WebElement firstNameField = driver.findElement(By.xpath("//input[@placeholder='First Name']"));
firstNameField.sendKeys("Tom");
Allure.step("Filling the field LASTNAME");
WebElement lastNameField = driver.findElement(By.xpath("//input[@placeholder='Last Name']"));
lastNameField.sendKeys(option);
Allure.step("Filling the field POSTCODE");
WebElement postCodeField = driver.findElement(By.xpath("//input[@placeholder='Zip/Postal Code']"));
postCodeField.sendKeys("123456");
Allure.step("Clicking on the submit button");
WebElement submitButtonCheckout = driver.findElement(By.xpath("//input[@type='submit']"));
submitButtonCheckout.click();
Allure.step("Checking that the checkout overview page is existed");
String checkoutTitle = driver.findElement(By.xpath("//span[@class='title'][contains(text(),'Checkout: Overview')]")).getText();
Assert.assertEquals(checkoutTitle,"Checkout: Overview");
driver.quit();
}
I don't know how to resolve this problem so my turns to resolve were comlicated. I tried to change catch (IOException e) into catch (IOException | NoSuchElementException e) in test lestener but it didn't help.
These tests with @DataProvider work well in case if I start it singly. But they don't work well if I try to use it with the whole suite.
Upvotes: 0
Views: 44