selenium - 使用 testNG 运行程序,第一次在字段中添加无效数据,然后清除,然后使用有效凭据登录
问题描述
执行脚本时出现错误,下面我提到了我运行的脚本,请检查并告诉我为什么会遇到这个错误
java.io.IOException: Access is denied
at java.base/java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.base/java.io.File.createNewFile(Unknown Source)
at org.testng.internal.Utils.writeFile(Utils.java:173)
at org.testng.internal.Utils.writeFile(Utils.java:149) atorg.testng.reporters.TestHTMLReporter.generateLog(TestHTMLReporter.java:320) atorg.testng.reporters.TestHTMLReporter.onFinish(TestHTMLReporter.java:40)
at org.testng.TestRunner.fireEvent(TestRunner.java:1250)
at org.testng.TestRunner.afterRun(TestRunner.java:1041)
at org.testng.TestRunner.run(TestRunner.java:628)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
我运行以执行测试和上面的代码是错误,执行上面和下面的脚本时出现错误我提到了我运行的脚本,请检查并让我知道为什么会遇到这个错误
package TestNG;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class testng {
WebDriver driver;
// Method 1: Open Brower say Firefox
@Test (priority = 1)
public void openBrowser() {
driver = new FirefoxDriver();
// public void launch() {
driver.get("URL");
}
@Test (priority = 2)
public void one() throws InterruptedException {
driver.findElement(By.xpath(".//*[@id='user_login']")).sendKeys("Invalid Email");
driver.findElement(By.xpath(".//*[@id='user_login_password']")).sendKeys("Invalid Password");
driver.findElement(By.xpath(".//*[@id='user_login_btn']")).click();
System.out.println("Error has occur wrong credentials");
}
@Test (priority = 3)
public void two() {
driver.findElement(By.xpath(".//*[@id='user_login']")).clear();
driver.findElement(By.xpath(".//*[@id='user_login_password']")).clear();
driver.findElement(By.xpath(".//*[@id='user_login']")).sendKeys("Valid");
driver.findElement(By.xpath(".//*[@id='user_login_password']")).sendKeys("Valid");
driver.findElement(By.xpath(".//*[@id='user_login_btn']")).click();
解决方案
你还没有设置geckodriver的路径。请在方法openBrowser()中设置驱动路径
可以使用以下代码设置驱动程序路径:
System.setProperty("webdriver.gecko.driver","path of geckodriver");
driver = new FirefoxDriver();
推荐阅读
- terraform - 将环境配置分离到不同的文件夹中,现在 Terraform 想要创建所有资源,就好像它不知道它们存在一样
- reactjs - NodeJS API 401未经授权
- javascript - 我如何将这个 js 函数用于每个相同的类元素的 document.querySelectorAll
- python - Python for循环内函数多个参数
- reactjs - 我如何修复新的反应应用程序模块解析失败错误
- spring-boot - JPA 和 Spring Boot 不生成数据库表
- javascript - 向 DataTables.js 列中的单元格添加引导属性
- php - 如何从我自己的网站在 Twitter 上嵌入图像?
- typescript - 可以在装饰器中推断或引用源类吗?
- marklogic - 为什么我没有获得多词部分查询的建议?