org.apache.commons.exec.ExecuteException:ChromeDriver Chrome Selenium和TestNG Suite出现错误,进程退出 [英] org.apache.commons.exec.ExecuteException: Process exited with an error with ChromeDriver Chrome Selenium and TestNG Suite

查看:80
本文介绍了org.apache.commons.exec.ExecuteException:ChromeDriver Chrome Selenium和TestNG Suite出现错误,进程退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过TestNG XML执行TestNG套件时,出现以下错误.

I am observing below error when I am executing TestNG suite through TestNG XML.

严重: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',操作系统名称:'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(本机方法)处 在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个

SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: -1073741502 (Exit value: -1073741502) FAILED CONFIGURATION: @BeforeMethod initializetest 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 at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:202) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:188) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at testclasses.BaseClass.initializetest(BaseClass.java:25) 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.invokeConfigurationMethod(Invoker.java:510) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) at org.testng.internal.Invoker.invokeMethod(Invoker.java:585) 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:1191) at org.testng.TestNG.runSuitesLocally(TestNG.java:1116) at org.testng.TestNG.run(TestNG.java:1024) 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) Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:33768/status] to be available after 20001 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197) ... 35 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask.get(FutureTask.java:205) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 36 more

对于10-12个测试,这些测试最初可以顺利运行,但稍后会失败,并显示上述错误消息.我希望这是配置版本的问题,但我无法找到它.

The tests run smoothly initially for 10-12 tests but fails later with the above error message. I am hoping this is some issue with the configuration versions but I am not able to find it out.

项目的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.请帮我解决这个问题,因为测试突然失败,使整个自动化脚本不稳定.

Java Version is java version "1.8.0_201". ChromeDriver 2.43.600210. Please help me with this issue as the tests are failing abruptly leaving the whole Automation Script unstable.

TestNG的组织如下:

TestNG is organized as below :

<?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编写的代码

Below is the code written in @BeforeMethod and @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();

    }

推荐答案

@kovid,您好. 让我们尝试逐步调试它:

@kovid, hi. Lets try to debug it in a step by step way:

2)确保您也使用最新的chromedriver

还可以共享testng.XML套件的组织方式并共享您尝试执行的测试代码吗?

Could You please also share testng.XML suite how its organized and share test code You're attempting to execute please?

从异常中我看到-它试图访问浏览器实例,并且由于某种原因它不可访问. 可能被称为
driver.close(); 或者 driver.quit();代码中的某个位置.

From the exception I see - its trying to reach browser instance and for some reason its non accessible. Might be called
driver.close(); or driver.quit(); Somewhere in the code.

关于testNG配置-您可以查看框架规范和/或<表示测试套件组织方式的href ="https://docs.experitest.com/display/public/TA/TestNG" rel ="nofollow noreferrer">示例.

And regarding testNG configuration - You may take a look in framework specs and/or example representing how test suite is organized.

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

Hope it be helpful for You, regards, Eugene

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

============== UPD 2019/03/02 In addition to the explicit versioning @debanjanB provided above ^^ , I'd recommend to re-work code a bit in the following way:

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

IMPROVEMENT #1 Driver init (I've separated this method with appropriate configs ; personally I'm using selenium GRID , but You may keep using Chromedriver You use in your code, I'd say its a matter of habbit):

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;
}

如果您需要执行驱动程序重新启动操作-您可以将驱动程序init和包裹在try-catch块中的driver.close()一起使用

And if You need to do driver-restart action - You may use driver init with driver.close() wrapped in try-catch block

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'标志):

So AfterMethod will look like(Please add 'alwaysRun=true' flag):

   @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" 标签):

Please modify testng XML a bit (please add parallel="false" tag explicitly in suite tag):

<?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处理启动)

IMPROVEMENT #3 (assumption) if that not helps. From experience, if for some tests chrome instance is started and many times closed and re-launched again - You may still have bunch of chromedriver.exe processes (hanging in Your system and preventing new chromedriver processed to start)

因此,如果您发现自己有很多进程,请在WIN中杀死它们-您可以调用以下命令:

So if You figure out that You have many processes, to kill them in WIN -You may call the command:

Taskkill /T /F /IM chromedriver.exe

因此,考虑到您在每种测试方法后每次都杀死您的chrome,您也可以在after方法中另外杀死任何chromedriver进程(解释

So considering that You 'kill' each time Your chrome after every test method, You may additionally kill any chromedriver processes in after method as well (explained here how to execute cmd wrapped in java code).

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

Hope that finally helps :) Regards, Eugene

这篇关于org.apache.commons.exec.ExecuteException:ChromeDriver Chrome Selenium和TestNG Suite出现错误,进程退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆