Java Cucumber在@before hook:NoClassDefFoundError期间失败

Java Cucumber在@before hook:NoClassDefFoundError期间失败,java,selenium,automation,cucumber,chrome-web-driver,Java,Selenium,Automation,Cucumber,Chrome Web Driver,打开Chrome浏览器后,Automation framework将不会继续执行.feature文件中的步骤(然后在之后关闭) GenericStepImplementation.java代码 @Before public void setUp() throws ConfigurationException, org.apache.commons.configuration.ConfigurationException { System.setProperty("webdriver.ch

打开Chrome浏览器后,Automation framework将不会继续执行.feature文件中的步骤(然后在之后关闭)

GenericStepImplementation.java代码

@Before
public void setUp() throws ConfigurationException, org.apache.commons.configuration.ConfigurationException
{
    System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    config = new XMLConfiguration("sample-object-config.xml");
}
package test_runner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
glue={"code_bindings"},
features="src/test/resources/features", 
plugin = {"pretty", "html:target/cucumber-html-report"})

public class RunAutoTest {

}
RunAutoTest.java代码

@Before
public void setUp() throws ConfigurationException, org.apache.commons.configuration.ConfigurationException
{
    System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    config = new XMLConfiguration("sample-object-config.xml");
}
package test_runner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
glue={"code_bindings"},
features="src/test/resources/features", 
plugin = {"pretty", "html:target/cucumber-html-report"})

public class RunAutoTest {

}
样本特征

Feature: Automation Test

@Login-Successful
Scenario: Login (Successful)
Given I go to "www.yahoo.com" URL
    Then I enter "m@yahoo.com" into "login.username" field and click tab
    Then I enter "1234567890" into "login.password" text field
    Then I clicked on "login.loginlink" login button
    Then I wait for "15" seconds
    And I will capture the page named "Login-Successful"
作为JUnit测试运行后,Chrome浏览器已打开,但未执行Sample.feature文件中的步骤。控制台还显示:

*Feature: Automation Test
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 11795
Only local connections are allowed.
Jan 07, 2019 6:00:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[31mFailure in before hook:[0m[31mGenericStepImplementation.setUp()[0m
[31mMessage: [0m[31mjava.lang.NoClassDefFoundError: org/apache/commons/collections/CollectionUtils
    at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:640)
    at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:635)
    at org.apache.commons.configuration.XMLConfiguration.initProperties(XMLConfiguration.java:596)
    at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:1009)
    at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:972)
只要换个颜色就行了
System.setProperty(“webdriver.chrome.ChromeDriver”,“C:\\Automation\\Webdrivers\\ChromeDriver.exe”)

您需要将
系统中的关键字。setProperty
行从
ChromeDriver
更改为
驱动程序,即更改:

System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
致:

当类在编译期间存在,但在运行时不存在时,会发生此异常


请确保您的类路径包含
org/apache/commons/collections/CollectionUtils
。类路径中可能缺少库
commons collection

似乎缺少apache commons collection库。您可以尝试将其添加到您的构建中。您可以从as获取库,以便将其添加到您的构建中,这取决于您使用的内容(maven、gradle等)@CalvinIyer我已下载commons-collections4-4.2 jar并添加到java构建路径。但它仍然不起作用。还有其他建议吗?根据上面的错误,您需要
commons集合
而不是
commons-collection4
库。@CalvinIyer等待。。我还会下载commons collection jar文件只是为了添加到java构建路径吗?它不起作用。同样的结果(还有其他建议吗?改成什么?我已经下载了commons-collections4-4.2 jar并添加到java构建路径。它仍然不起作用。还有其他建议吗?我看到你找到了上面的答案。为你高兴!