0
我正在嘗試將硒與彈簧集成。如果在pom.xml中沒有添加彈簧依賴關係,下面的代碼完美工作。但如果我像下面添加spring引導依賴項(我沒有在這裏添加黃瓜春天,我從eclipse工作區中刪除了所有springcontext xml,cusumber xml),並且運行相同的測試而不修改任何東西,它會打開IE測試窗口http://localhost:36359/然後出錯控制檯如下「org.openqa.selenium.remote.SessionNotFoundException:會話null不存在(警告:服務器沒有提供任何堆棧跟蹤信息)」。org.openqa.selenium.remote.SessionNotFoundException:會話null不存在
我甚至嘗試通過在springcontext中初始化webdriver來替換@Before方法來添加所有的Spring註解;但仍然是相同的行爲。有人可以幫我解決這個問題。我使用的硒3.4.0版本
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.4.3.RELEASE</version>
<relativePath />
</parent>
public class ScenarioOutlineStepDef {
WebDriver driver;
@Before()
public void setUp() {
System.setProperty("webdriver.ie.driver", "C:/IEDriverServer-64.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
dc.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
dc.setJavascriptEnabled(true);
dc.setBrowserName("internet explorer");
driver = new InternetExplorerDriver(dc);
}
@Given("^user navigates to Pricing Portal$")
public void goToPricingPortal() {
driver.navigate().to(
"xyz.com;
}
@When("^I enter Username as \"([^\"]*)\" and Password as \"([^\"]*)\"$")
public void I_enter_Username_as_and_Password_as(String arg1, String arg2) {
driver.findElement(By.id("txtUserDefault")).sendKeys(arg1);
driver.findElement(By.id("txtPassDefault")).sendKeys(arg2);
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
}
@Then("^login should be unsuccessful$")
public void validateRelogin() {
if (driver.getCurrentUrl().equalsIgnoreCase(
"xyz.com")) {
System.out.println("Test Pass");
} else {
System.out.println("Test Failed");
}
// driver.close();
}
DesiredCapabilities不應該是一個問題;因爲它沒有與我在這裏發佈的代碼進行彈簧整合。我通過刪除彈簧引導並直接在Maven pom中添加所有依賴於彈簧的罐子來解決此問題。 – Ponns