gpt4 book ai didi

java - selenium webdriver 中的多个程序执行不起作用

转载 作者:行者123 更新时间:2023-11-30 06:30:35 25 4
gpt4 key购买 nike

selenium WebDriver 中的多个程序执行不起作用。我编写了 1 个 testNG xml 文件和 2 个 java 类。我尝试从 xml 文件运行这两个 java 类。但它不起作用。

XML 代码:

<suite name="Suite">
<test name="SIT">
<classes>
<class name="testng1.NewTest"/>
<class name="testng1.NewTest2"/>
</classes>
</test>
</suite>

现在“NewTest.java”类:

package testng1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class NewTest {
public static WebDriver driver;
@BeforeTest
public void launch()
{
System.setProperty("WebDriver.ie.driver", "C:\\Users\\rprem\\Downloads\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
System.out.println("BeforeTest Method");
}
@Test
public void gmail()
{
driver.get("https://gmail.com");
System.out.println("Gmail was launched");
}
@AfterTest
public void quit()
{
driver.quit();
System.out.println("AfterTest Method");
}
}

现在“NewTest2.java”:

package testng1;
import org.testng.annotations.Test;
public class NewTest2 extends NewTest
{
@Test
public void yahoo()
{
driver.get("https://yahoo.com");
System.out.println("yahoo site was opened");
}
}

当我使用 testng 运行 xml 文件时,我收到以下错误消息:

错误消息:

FAILED CONFIGURATION: @BeforeTest launch java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) at testng1.NewTest.launch(NewTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

SKIPPED CONFIGURATION: @AfterTest quit
SKIPPED: gmail
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more

information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) at testng1.NewTest.launch(NewTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

SKIPPED: gmail
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more

information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) at testng1.NewTest.launch(NewTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

SKIPPED: yahoo
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more

information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) at testng1.NewTest.launch(NewTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

===============================================
testng1
Tests run: 3, Failures: 0, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================


===============================================
practice by packages
Total tests run: 3, Failures: 0, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================

最佳答案

xml 文件中删除以下行。因为你的类NewTest2扩展了NewTest所以,这里不需要写。

<class name="testng1.NewTest"/>

用此替换您的 xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite guice-stage="DEVELOPMENT" name="Test">
<test verbose="2" name="Dummy">
<classes>
<class name="testng1.NewTest2"/>
</classes>
</test>
</suite>

IE 浏览器 中执行脚本之前,请更正这些设置。

Go to settings -> Internet options -> Security tab -> Make this option Enable for all four zones. (Enable Protected Mode)

请参阅下图以更改此设置。

enter image description here

你的执行代码将是这样的。

enter image description here

执行:- 如果您运行上面的 xml 文件,您的代码将以这种方式执行。

1)BeforeTest方法
2)Gmail
3)雅虎
4)AfterTest方法

关于java - selenium webdriver 中的多个程序执行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46234351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com