我使用TestNG创建了一个测试类,在这个类中我定义了5个测试方法。当我运行测试时,TestNG控制台显示已经执行了总共5个中的3个场景(参见下图)。 registroNovo和tabulacaoTratamento方法未执行。 当我关闭浏览器(Chrome)时,TestNG控制台会显示以下错误屏幕。
Eclipse控制台显示以下错误消息:
.mjs
有没有人见过这种错误?
基本上我创建了4个类:
BaseTest 类,其中包含所有测试类通用的所有方法:
org.openqa.selenium.WebDriverException: chrome not reachable
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'RJO-BCC-C2A-H21', ip: '10.5.79.38', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\lsnpere\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.87, webStorageEnabled: true}
Session ID: 32d0291ab5ecaa1141f9997771edcd95
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:987)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:808)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:804)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at page.RegistroNovo.registroNovo(RegistroNovo.java:25)
at test.ValidarFaturamentoRoamingTest.registroNovo(ValidarFaturamentoRoamingTest.java:34)
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:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
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)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
测试类 ValidarFaturamentoRoamingTest 扩展了类 BaseTest :
public class BaseTest {
public static WebDriver driver;
public static WebDriverWait wait;
@BeforeClass
public static void setup() {
System.setProperty("webdriver.chrome.driver", "e:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 15);
driver.manage().window().maximize();
}
@AfterClass
public static void tearDown() throws InterruptedException {
Thread.sleep(5000);
driver.findElement(By.id("mn_sair"));
driver.quit();
}}
类 TratOsFatRoamPage ,它扩展了类 BasePage 。
public class ValidarFaturamentoRoamingTest extends BaseTest {
@Test(priority=0)
public void acessarBkoMais() {
HomePage homepage = new HomePage(driver, wait);
homepage.abrirBkoMais();
}
@Test(priority=1)
public void logarBkoMais() {
LoginPage logar = new LoginPage(driver, wait);
logar.loginBkoMais("000000", "000000");
}
@Test(priority=2)
public void logarEstrategia() {
LogarEstrategiaPage logarEstrategia = new LogarEstrategiaPage(driver, wait);
logarEstrategia.logarEstrategia();
}
@Test(priority=3)
public void registroNovo() {
RegistroNovo registroNovo = new RegistroNovo(driver, wait);
registroNovo.registroNovo();
}
@Test(priority=4)
public void tabulacaoTratamento() {
TratOsFatRoamPage rt = new TratOsFatRoamPage(driver, wait);
rt.TratOsFatRoam();
}}
类 BasePage ,其中包含所有常见类的方法:
public class TratOsFatRoamPage extends BasePage {
public TratOsFatRoamPage(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
}
String idMotivo = "cboMotivo";
String idSubMotivo = "cboSubMotivo";
String idStatus = "cboStatus";
String qtdNumerosFaturas = "txtQtdFaturas";
String qtdNumerosCotas = "txtQtdContas";
String idObservacao = "txtObservacao";
String idSalvar = "btnSalvar";
public void TratOsFatRoam() {
writeText(By.id(qtdNumerosFaturas),"Teste 2018");
writeText(By.id(qtdNumerosCotas), "2018-2");
}}
答案 0 :(得分:0)
org.openqa.selenium.WebDriverException:chrome无法访问
这意味着由于某种原因,驱动程序和chrome实例之间没有发生通信;在你的情况下,原因是你在3次测试运行后手动关闭它。 并且您的TestNG控制台显示错误屏幕,因为由于关闭浏览器而未运行最后2个测试用例。
对于那篇文章的一些代码。
答案 1 :(得分:-1)
此错误消息......
org.openqa.selenium.WebDriverException: chrome not reachable
...表示 ChromeDriver 无法与 WebBrowser 进行通信,即 Chrome浏览会话。
您的主要问题是您使用的二进制文件版本之间的不兼容性,如下所示:
因此 JDK v8u131 , Selenium Client v3.8.0 , ChromeDriver v2.40 和 Chrome之间存在明显的不匹配浏览器v67.0