访问被拒绝异常:testNG java.IOException



我是硒
自动化测试的新手,在java maven项目中执行testNG代码时,我遇到了以下问题:

[Utils] [ERROR] Access is denied
*java.io.IOException*: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at org.testng.internal.Utils.writeFile(*Utils.java:176*)
at org.testng.internal.Utils.writeFile(*Utils.java:149*)
at org.testng.reporters.SuiteHTMLReporter.generateTableOfContents(SuiteHTMLReporter.java:611)
at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:69)
at org.testng.TestNG.generateReports(TestNG.java:1097)
at org.testng.TestNG.run(TestNG.java:1022)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
[Utils] [ERROR] Access is denied
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at org.testng.internal.Utils.writeFile(Utils.java:176)
at org.testng.internal.Utils.writeFile(Utils.java:149)
at org.testng.reporters.SuiteHTMLReporter.generateXmlFile(*SuiteHTMLReporter.java:101*)
at org.testng.reporters.SuiteHTMLReporter.generateReport(*SuiteHTMLReporter.java:79*)
at org.testng.TestNG.generateReports(*TestNG.java:1097*)
at org.testng.TestNG.run(TestNG.java:1022)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
[Utils] [ERROR] Access is denied
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at org.testng.internal.Utils.writeFile(Utils.java:176)
at org.testng.internal.Utils.writeFile(Utils.java:149)
at org.testng.reporters.SuiteHTMLReporter.generateIndex(SuiteHTMLReporter.java:170)
at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:82)
at org.testng.TestNG.generateReports(TestNG.java:1097)
at org.testng.TestNG.run(TestNG.java:1022)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

我的分类如下所示: 测试库.java

public class TestBase {
public static WebDriver driver=null;
public static Properties prop;
public TestBase() {
try {
prop = new Properties();
FileInputStream ip = new FileInputStream(
System.getProperty("user.dir")+"\src\main\java\com\qa\config\config.properties");
prop.load(ip);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void initialization() {
String browserName = prop.getProperty("browser");
if (browserName.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "E:\Automation_Testing\AutomationTest\chromedriver.exe");
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT,TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
}

在这门课中,我编写了执行代码以在我的应用程序中创建一个学生。 班级名称 : 学生页面测试.java

public class StudentPageTest extends TestBase{
LoginPage loginpage;
StudentPage studentpage;
public StudentPageTest() throws Exception {
super();
}
@BeforeTest
public void setUp() throws IOException {
initialization();
loginpage = new LoginPage();
studentpage = new StudentPage();
}
@Test(priority = 1)
public void loginTest() throws InterruptedException {
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
}
@Test(priority = 2)
public void addStudent() throws InterruptedException, IOException {
studentpage = new StudentPage();
Thread.sleep(8000);
studentpage.clickBy(studentpage.studentMenu);
Thread.sleep(10000);
studentpage.add_student();
}
}

我调用此方法以添加学生此方法的功能是它应该在我的应用程序中创建一个学生

public void add_student() throws InterruptedException, IOException {
clickBy(add_studentBtn);
Thread.sleep(10000);
sendText(stud_name, "Nayan");
Thread.sleep(2000);
sendText(stud_contactnum, "4565434455");
Thread.sleep(2000);
sendText(stud_email, "n1@gmail.com");
Thread.sleep(2000);
sendText(parentname, "Prakash");
Thread.sleep(2000);
sendText(parent_contactnum, "5543654344");
Thread.sleep(2000);
sendText(parent_email, "prksh@gmail.com");
Thread.sleep(2000);
clickBy(assigncourselink);

}

如果您需要更多分析,请发表评论。

在运行 TestNG 时,不一致地抛出错误消息"测试 NG java.io.IOException:访问被拒绝">

最新更新