【问题标题】:org.apache.commons.exec.ExecuteException: Process exited with an error with ChromeDriver Chrome Selenium and TestNG Suiteorg.apache.commons.exec.ExecuteException:进程退出,出现 ChromeDriver Chrome Selenium 和 TestNG Suite 错误
【发布时间】:2019-07-22 12:51:41
【问题描述】:

当我通过 TestNG XML 执行 TestNG 套件时,我观察到以下错误。

严重:org.apache.commons.exec.ExecuteException:进程退出 一个 错误:-1073741502(退出值:-1073741502) 配置失败:@BeforeMethod 初始化测试 org.openqa.selenium.WebDriverException:等待驱动程序服务器启动超时。 构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:17:03' 系统信息:主机:'PDC2LAP-7173253',ip:'10.170.10.178',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0', java.version: '1.8.0_162' 驱动程序信息:driver.version:ChromeDriver 在 org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:202) 在 org.openqa.selenium.remote.service.DriverService.start(DriverService.java:188) 在 org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) 在 org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) 在 testclasses.BaseClass.initializetest(BaseClass.java:25) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) 在 org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) 在 org.testng.internal.Invoker.invokeMethod(Invoker.java:585) 在 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816) 在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124) 在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 在 org.testng.TestRunner.privateRun(TestRunner.java:774) 在 org.testng.TestRunner.run(TestRunner.java:624) 在 org.testng.SuiteRunner.runTest(SuiteRunner.java:359) 在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) 在 org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) 在 org.testng.SuiteRunner.run(SuiteRunner.java:261) 在 org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 在 org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1191) 在 org.testng.TestNG.runSuitesLocally(TestNG.java:1116) 在 org.testng.TestNG.run(TestNG.java:1024) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) 原因:org.openqa.selenium.net.UrlChecker$TimeoutException: 等待 [http://localhost:33768/status] 可用时超时 20001 毫秒后 在 org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) 在 org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197) ... 35 更多 引起:java.util.concurrent.TimeoutException 在 java.util.concurrent.FutureTask.get(FutureTask.java:205) 在 com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156) 在 org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 36 更多

10-12 次测试的测试最初运行顺利,但后来因上述错误消息而失败。我希望这是配置版本的一些问题,但我无法找到它。

项目有以下 POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>PageObjects</groupId>
  <artifactId>CustomerPortal</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>CustomerPortal</name>
  <url>http://maven.apache.org</url>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.0.9</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.6</version>
</dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>3.141.59</version>
</dependency>
   <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.0.1</version>
</dependency>
   <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>

<dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.9.8</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Java 版本是 Java 版本“1.8.0_201”。 Chrome 驱动程序 2.43.600210。请帮助我解决这个问题,因为测试突然失败导致整个自动化脚本不稳定。

TestNG 组织如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="CustomerPortalTestSuite-SIT2">
  <test thread-count="5" name="CustomerPortalTestExecution">
    <classes>
    <class name="testclasses.CustomerPortalSupportTest"/>
    <class name="testclasses.CustomerPortalAccountTest"/>
    <class name="testclasses.CustomerPortalBillingTest"/>
    <class name="testclasses.CustomerPortalHomeTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

下面是@BeforeMethod和@AfterMethod写的代码,

@BeforeMethod
public void initializetest() {
        System.setProperty("webdriver.chrome.driver", "C:\\Downloads\\ChromeDriverLatest\\chromedriver.exe");
        driver =new ChromeDriver();
        wait = new WebDriverWait(driver,10);

    }

    @AfterMethod
    public void endTest() throws IOException, Exception {
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File("c:\\SeleniumScreenshots\\" + count +".jpg"));
            count++;
        Thread.sleep(5000);
        driver.quit();
        driver=null;
    }

下面的测试类示例:

@DataProvider(name="editAccDetails")
    public Object[][] logincreds(){
        Object[][] data = new Object[1][2];
        data[0][0] = "test";
        data[0][1] = "test";
        return data;
    }


    @Test(priority=1, dataProvider="editAccDetails")
    public void Details(String UsernameDP, String PasswordDP) throws Exception {
            Login TS1 = new Login(driver,wait);
            TS1.test(UsernameDP, PasswordDP);
            HomePage TS2 = new HomePage(driver,wait);
            TS2.test();
            AccountPages TS3 = new AccountPages(driver,wait);
            TS3.Details();

    }

【问题讨论】:

  • 分享你的完整Java测试类
  • 在@waqar 上方添加
  • BaseClass.java 的第 25 行是什么?
  • driver=new ChromeDriver();在我的代码的第 25 行。 @waqar
  • 请添加完整的类代码。

标签: java selenium google-chrome testng selenium-chromedriver


【解决方案1】:

@kovid,嗨。 让我们尝试逐步调试它:

您能否也分享一下testng.XMLsuite 它是如何组织和分享您尝试执行的测试代码的?

从我看到的异常中 - 它试图访问浏览器实例并且由于某种原因它无法访问。 可能被称为
driver.close(); 要么 driver.quit(); 代码中的某处。

关于 testNG 配置 - 您可以查看 framework specs 和/或 example 代表测试套件的组织方式。

希望对你有帮助, 问候, 尤金

=============== UPD 2019/03/02 除了上面提供的显式版本控制@debanjanB ^^ 之外,我建议通过以下方式重新编写代码:

改进 #1 驱动程序初始化(我已将此方法与适当的配置分开;我个人使用的是 selenium GRID,但您可以继续使用 Chromedriver 您在代码中使用,我会说这是习惯问题):

public static WebDriver driverSetUp(WebDriver driver) throws MalformedURLException {

ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(ChromeOptions.CAPABILITY, options);
//System.setProperty("webdriver.chrome.driver", System.getProperty("user.home")+"/Documents/:Proj_folder:/chromedriver");
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
capability.setBrowserName("chrome");
capability.setCapability("nativeEvents", true);
LoggingPreferences logs = new LoggingPreferences();
//Javascript console logs from the browser
logs.enable(LogType.BROWSER, Level.WARNING);
logs.enable(LogType.PERFORMANCE, Level.ALL);
capability.setCapability(CapabilityType.LOGGING_PREFS, logs);
String webDriverURL = "http://" + environmentData.getHubIP() + ":" + environmentData.getHubPort() + "/wd/hub";
log.info("creating driver instance on the URL :#### " + webDriverURL);
driver = new RemoteWebDriver(new URL(webDriverURL), capability);
driver.manage().window().maximize();
return driver;}





public static WebDriver driverInit(WebDriver driver, String startingUrl) throws MalformedURLException {
    driver = DriverInit.driverSetUp(driver);
    driver.get(startingUrl);

    return driver;
}

如果您需要执行驱动程序重新启动操作 - 您可以使用包含在 try-catch 块中的 driver.close() 驱动程序初始化

public static WebDriver driverRestart(WebDriver driver, String startingUrl) throws MalformedURLException {
    try {
        driver.close();
    } catch (WebDriverException e) {
        log.error("#### oops, seems driver instance have been already closed. Doing re-initialization right now!", e.getMessage(), e);
    }
    return driverInit(driver, startingUrl);
}

所以 AfterMethod 看起来像(请添加 'alwaysRun=true' 标志):

   @AfterMethod(alwaysRun = true)
    public void closeDriverInstance() {
        try {
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File(
String.format("c:\\SeleniumScreenshots\\%s.jpg", count)));
            driver.close();
        } catch (Exception e) {
            log.info(" oops, it seems that driver instance have been already closed.");
        }
    }

改进 #2

请稍微修改一下 testng XML(请在套件标签中显式添加 parallel="false" 标签):

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

<suite name="CustomerPortalTestSuite-SIT2" parallel="false" thread-count="5" verbose="8">
  <test name="CustomerPortalTestExecution">
    <classes>
    <class name="testclasses.CustomerPortalSupportTest"/>
    <class name="testclasses.CustomerPortalAccountTest"/>
    <class name="testclasses.CustomerPortalBillingTest"/>
    <class name="testclasses.CustomerPortalHomeTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite --> 

改进#3(假设) 如果那没有帮助。根据经验,如果对于某些测试,chrome 实例已启动并多次关闭并重新启动 - 您可能仍然有一堆 chromedriver.exe 进程(挂在您的系统中并阻止新的 chromedriver 处理启动)

所以如果你发现你有很多进程,在 WIN 中杀死它们 - 你可以调用命令:

Taskkill /T /F /IM chromedriver.exe

因此,考虑到您在每次测试方法之后每次都“杀死”您的 chrome,您还可以在 after 方法中杀死任何 chromedriver 进程(解释了here 如何执行包装在 java 代码中的 cmd)。

希望最终有所帮助:) 问候, 尤金

【讨论】:

  • 感谢@eugene 您的意见。 Selenium Server 与 ChromeDriver 一起是最新的。我已经在上面添加了 TestNG.XML 结构。
  • @KovidMehta,您能否分享一下您在@BeforeSuite @BeforeTest @BeforeClass @BeforeMethod 和后续方法中调用了什么方法/代码?
  • 在Eugene上面的BeforeMethod和AfterMethod中添加了代码。
  • 快速提问 - 您需要让测试并行运行还是应该以一对一的模式执行?
  • 谢谢@eugene。这创造了奇迹。刚刚对 TestNG XML 和 AfterMethod 进行了更改并运行了该套件。它运行良好,执行了所有测试,没有任何错误。非常感谢您提供如此详细的逐步解释。将尽快尝试实现 CMD 部分。
【解决方案2】:

此错误消息...

 org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. 
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' 
System info: host: 'PDC2LAP-7173253', ip: '10.170.10.178', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162' 
Driver info: driver.version: ChromeDriver

...暗示 ChromeDriver 无法与 WebElement 交互。

您的主要问题是您使用的二进制文件版本之间的不兼容性,如下所示:

虽然你提到了使用:

  • Java版本是java版本“1.8.0_201”
  • ChromeDriver 2.43.600210

跟踪日志说:

java.version: '1.8.0_162'

当您使用 Selenium v​​3.141.59 时,组件不兼容。


解决方案

【讨论】:

  • 感谢@debanjan 的投入。尝试更新上述所有内容,但仍然看到该错误。在对 testng XML 和 After 方法进行更改后,我能够运行套件。
猜你喜欢
  • 1970-01-01
  • 2022-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-01
  • 1970-01-01
  • 2018-08-18
相关资源
最近更新 更多