findelement selenium引发的java警告webdriverexception
当我运行所有测试时,其中一些会崩溃,我在控制台中收到一个通知“警告:findElement引发的WebDriverException(by.xpath:some locator)”和“会话ID为null。在调用quit()后使用WebDriver?”。我已经得出结论,失败的测试是那些调用使用它的方法的测试。但是,我很困惑,因为当我单独运行每个测试时,每个测试都通过了,即使是那些在一起运行时失败的测试。有人知道我怎么解决这个问题吗?谢谢
代码:
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();
}
共 (0) 个答案