Когда я запускаю все тесты, некоторые из них производят sh, и в консоли появляется уведомление «ПРЕДУПРЕЖДЕНИЕ: WebDriverException, выдаваемый findElement (By.xpath: some locator)» и «Идентификатор сеанса равен нулю. Использование WebDriver после вызова quit ()? ". Я пришел к выводу, что провальные тесты - это те, которые вызывают методы, в которых был использован WebDriverWait. Но я в замешательстве, потому что, когда я запускаю каждый тест по отдельности, каждый проходит, даже те, которые не прошли, когда я провел их вместе. Кто-нибудь знает, как я мог решить эту проблему? Спасибо.
Код:
package methods;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
public class PropertyFile extends SetUp {
public static Properties properties;
public static InputStream inputStream;
public ExtentReports report;
public ExtentTest test;
@BeforeMethod
public void readPropertiesFile() {
try {
String workingDir = System.getProperty("user.dir");
System.out.println(workingDir);
properties = new Properties();
inputStream = readFile("application.properties");
properties.load(inputStream);
//uzima vrednost do chromeDrivera
String driverPath = properties.getProperty("DRIVER_PATH_WIN_CHROME");
//uzima vrednost do report-a
String reportPath = properties.getProperty("FOLDER_REPORT_PATH");
System.setProperty(properties.getProperty("DRIVER_NAME_CHROME"),
workingDir +
driverPath);
System.out.println(workingDir + driverPath);
// kreiranje reporta
report = new ExtentReports(workingDir + reportPath, false);
//URL do sajta koji testiramo
report.addSystemInfo("URL", "https://demoqa.com/");
createDriver();
getDriver().manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// govorimo pretrazivacu koju stranicu da otvori
getDriver().get(properties.getProperty("URL"));
} catch (Exception e) {
System.out.println("Failed to instantiate and load properties and chrome
driver!");
}
}
@Test
public void check(){
test = report.startTest("exampe");
slider.moveSliderTo(100);
test.log(LogStatus.INFO, "Slider was moved");
MainMethods.waitElementToBeVisible(By.xpath("//span[@style = 'left:
20%;']"));
test.log(LogStatus.INFO, "Position of slider is on 20%");
}
@AfterMethod
public void tearDown(ITestResult testResult) throws Exception {
if (testResult.getStatus() == ITestResult.FAILURE) {
String path = methods.Screenshot.takeScreenshot(getDriver(),
methods.Screenshot.generateFileName(testResult));
String imgPath = test.addScreenCapture(path);
test.log(LogStatus.FAIL, "Test case which FAILED is " +
testResult.getName(),
imgPath);
test.log(LogStatus.FAIL, "Method which FAILED is " +
testResult.getThrowable());
} else if (testResult.getStatus() == ITestResult.SUCCESS) {
test.log(LogStatus.PASS, "Test case which PASSED IS " +
testResult.getName());
} else if (testResult.getStatus() == ITestResult.SKIP) {
test.log(LogStatus.PASS, "Test case which SKIPPED IS " +
testResult.getName());
}
getDriver().manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
quitDriver();
report.endTest(test);
report.flush();
}