我正在尝试将硒与春天结合。如果pom.xml中没有添加spring依赖项,则下面的代码非常有用。但是,如果我像下面一样添加spring boot依赖项(我没有在这里添加黄瓜弹簧,我从eclipse工作区删除了所有springcontext xml,cusumber xml)并运行相同的测试而不修改任何内容,它打开一个IE测试窗口http://localhost:36359/然后在控制台中出错,如下面的“org.openqa.selenium.remote.SessionNotFoundException:session null不存在(警告:服务器没有提供任何堆栈跟踪信息)”。
我甚至尝试通过在springcontext中启动webdriver来添加所有spring注释替换@Before方法;但仍然是相同的行为。有人可以帮我解决这个问题。我正在使用selenium 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();
}
答案 0 :(得分:0)
手动执行
为所有区域设置相同的安全级别。尝试这个步骤
或者像这样使用DesiredCapabilities
DesiredCapabilities IEcaps = DesiredCapabilities.internetExplorer();
IEcaps .setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
File SrcFile= new File("E:\\Sankalp\\IE\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", SrcFile.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver(IEcaps );
driver.get("Your URL");
driver.quit();