提问人:Automation Engineer 提问时间:1/7/2019 最后编辑:Loïc Le DoyenAutomation Engineer 更新时间:1/8/2019 访问量:1733
Cucumber 在挂钩期间失败@before:NoClassDefFoundError
Cucumber fails during @before hook : NoClassDefFoundError
问:
打开 Chrome 浏览器后,自动化框架不会继续在 .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");
}
RunAutoTest.java 代码
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 "[email protected]" 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 Test 运行后,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)
答:
-1赞
Jainik Bakaraniya
1/7/2019
#1
只需更改System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
评论
0赞
Automation Engineer
1/8/2019
换成什么?
0赞
undetected Selenium
1/7/2019
#2
您需要将行中的关键字从 to driver
更改为更改:System.setProperty
ChromeDriver
System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
自:
System.setProperty("webdriver.chrome.driver","C:\\Automation\\Webdrivers\\chromedriver.exe");
only ^^^driver^^^
评论
0赞
Automation Engineer
1/8/2019
它没有用。只是相同的结果。:(还有其他建议吗?
0赞
Mikhail Kopylov
1/8/2019
#3
https://docs.oracle.com/javase/7/docs/api/java/lang/NoClassDefFoundError.html
当类在编译期间存在但在运行时不存在时,就会发生此异常。
请确保您的类路径包含 .类路径中可能缺少库。org/apache/commons/collections/CollectionUtils
commons-collections
评论
0赞
Automation Engineer
1/8/2019
我已经下载了 commons-collections4-4.2 jar 并添加到 java 构建路径中。它仍然不起作用。还有其他建议吗?
0赞
Mikhail Kopylov
1/8/2019
我看到你已经在上面找到了答案。为你感到高兴!😊
评论
commons-collection
commons-collection4