我用java编写了一个简单的代码,它将打开chrome浏览器并验证其标题。在这里,我使用了Jbehave(BDD(概念来实现它。
我面临的问题是我无法运行我的配置文件。
这是我的 .story 文件
narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development
Scenario: A Scenario to open google.com
Given I open a browser
When I enter the https://www.google.com
Then google is displayed
这是我的故事情节的java代码
import java.util.concurrent.TimeUnit;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DebugPluginSteps {
WebDriver driver = new ChromeDriver();
@Given("I open a browser")
public void openTheBrowser() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@When("I enter $url")
public void typeTheUrl(String url) {
driver.get(url);
}
@Then("$title is displayed")
public void debugStepForThenTest(String title) {
if (driver.getTitle() == title) {
System.out.println("Title matched");
} else {
System.out.println("Title is not matching");
}
}
}
}
这是我的配置文件。
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStory;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
public class MyLinkedListStory extends JUnitStory {
@Override
public Configuration configuration() {
return new MostUsefulConfiguration();
}
@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new DebugPluginSteps());
}
}
控制台输出:
Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 29264
Only local connections are allowed.
[1578918833.831][WARNING]: Timed out connecting to Chrome, retrying...
Jan 13, 2020 6:03:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]
Generating reports view to 'C:UsersDesktopSelenium 201SimpleJbehavetargetjbehave' using formats '[]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending)
此错误消息...
Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 29264
Only local connections are allowed.
[1578918833.831][WARNING]: Timed out connecting to Chrome, retrying...
Jan 13, 2020 6:03:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
。暗示ChromeDriver无法启动/生成新的浏览上下文,即Chrome浏览器会话。
您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
- 您正在使用的 chromedriver = 2.43
- chromedriver=2.43的发行说明明确提到了以下内容:
支持铬 v69-71
- 大概您正在使用更新的chrome = 79.0
- ChromeDriver v79.0的发行说明明确提到了以下内容:
支持Chrome版本79
- 我们不知道您的硒客户端版本。
因此,ChromeDriver v2.43和Chrome浏览器v79.0之间存在明显的不匹配
。溶液
确保:
- JDK已升级到当前级别 JDK 8u222。
- 硒已升级到当前级别 版本 3.141.59。
- ChromeDriver已更新到当前的 ChromeDriver v79.0.3945.36 级别。 Chrome
- 已更新到当前的Chrome 版本 79.0级别。(根据 ChromeDriver v79.0 发行说明(
- 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
- 如果基本 Web 客户端版本太旧,请将其卸载并安装最新的 GA 和已发布版本的Web 客户端。