org.apache.commons.exec.ExecuteException:流程退出与Chro

2019-09-29 02:15发布

我观察下面的错误,当我通过TestNG的XML执行TestNG的套件。

重度:org.apache.commons.exec.ExecuteException:过程返回一个错误:-1073741502(退出值:-1073741502)失败配置:@BeforeMethod initializetest org.openqa.selenium.WebDriverException:超时等待司机服务器启动。 构建信息:版本: '3.141.59',修订版: 'e82be7d358',时间: '2018-11-14T08:17:03' 系统信息:主机: 'PDC2LAP-7173253',IP:'10 .170.10.178' ,OS 。名称: '视窗10',os.arch: 'AMD64',os.version:'10 0.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)在识别TestClass es.BaseClass.initializetest(BaseClass.java:25)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在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(祈求的.java:510)处org.testng.internal.Invoker.invokeMethod(Invoker.java:585)在org.testng.internal.Invoker.invokeTestMethod(org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) 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.TestRunne r.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)引起的:有机.openqa.selenium.net.UrlChecker $ TimeoutException异常:超时等待[ HTTP://本地主机:33768 /状态]是后org.openqa.selenium.net.UrlChecker.waitUntilAvailable 20001个毫秒可用(UrlChecker.java:100 )在org.openqa.sel java.util.concurrent.TimeoutException在java.util.concurrent.FutureTask.get(FutureTask.java:205)在COM:enium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197)...... 35多所致.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”。 ChromeDriver 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();

    }

Answer 1:

@kovid,喜。 让我们尝试调试它在一步步方式:

  • 1)更新硒服务器到最新的一个版本

  • 2)确保您使用最新chromedriver以及

请你也同意testng.XML套件及其如何组织和共享测试代码,你试图执行吗?

从我看到的例外 - 它试图达到的浏览器实例,由于某种原因其非访问。 可能被称为
driver.close();driver.quit(); 在某处的代码。

而关于TestNG的配置-你可以采取一看框架,规范和/或例如代表测试套件是如何组织的。

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

============== UPD 2019年3月2日除了上面^^提供明确的版本@debanjanB,我建议你重新工作代码通过以下方式有点:

改进#1驱动的init(我已经分开这个方法适当CONFIGS;个人我使用硒网格,但您可以继续使用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;
}

如果你需要做司机重新启动操作-您可以使用驱动程序初始化与driver.close()包装在try-catch块

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 =真正的”标志):

   @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位(请加平行=“假”标签中明确标记套件):

<?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(假设)如果不是帮助。 从以往的经验,如果一些测试铬实例启动并多次关闭并重新启动-你可能仍然有一堆chromedriver.exe过程(挂在您的系统和预防处理,以启动新chromedriver)

所以,如果你弄清楚,你有很多方法,杀死他们在WIN - 你可以调用命令:

Taskkill /T /F /IM chromedriver.exe

因此,考虑到你每天的测试方法后,“杀”每次你的浏览器,您可以另外在方法后,如杀任何chromedriver过程(解释这里如何执行CMD包裹在Java代码中)。

希望终于帮助:)问候,尤金



Answer 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

Tracelogs说:

java.version: '1.8.0_162'

当你正在使用Selenium v3.141.59的组件不兼容。


  • 升级JDK近期水平JDK 8u201
  • 升级ChromeDriver当前ChromeDriver v2.46水平。
  • Chrome v71-73水平之间的Chrome版本。 ( 如每ChromeDriver v2.46发行说明 )


文章来源: org.apache.commons.exec.ExecuteException: Process exited with an error with ChromeDriver Chrome Selenium and TestNG Suite