【发布时间】:2017-03-29 13:24:33
【问题描述】:
当我的测试脚本尝试打开 Internet Explorer 时,出现错误。
这是我的测试脚本:
package selenium;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
public class RegistrationTest{
public int a = 1;
@Test //This is JUnit annotation
public void testRegister(){
WebDriver driver ;
System.setProperty("webdriver.ie.driver","IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.navigate().to("http://newtours.demoaut.com/");
driver.findElement(By.linkText("REGISTER")).click();
driver.findElement(By.name("firstName")).sendKeys("User1");
driver.findElement(By.name("lastName")).sendKeys("Surname1");
driver.findElement(By.name("phone")).sendKeys("123456789");
driver.findElement(By.name("userName")).sendKeys("user1@test.com");
driver.findElement(By.name("address1")).sendKeys("Test Address");
driver.findElement(By.name("city")).sendKeys("Test City");
Select select = new Select(driver.findElement(By.name("country")));
select.selectByVisibleText("ANGOLA");
driver.findElement(By.name("email")).sendKeys("user1@test.com");
driver.findElement(By.name("password")).sendKeys("user1");
driver.findElement(By.name("confirmPassword")).sendKeys("user1");
driver.findElement(By.name("register")).click();
driver.quit();
}
}
我的 POM.xml 是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cgi.nouguierc</groupId>
<artifactId>WD-Automation</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>selenium.MainJar</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
当我启动 RegistrationTest 时,互联网正在打开,转到地址“http://newtours.demoaut.com/”,然后什么也不做。
在控制台中我有一些错误:
Started InternetExplorerDriver server (64-bit)
3.0.0.0
Listening on port 44920
Only local connections are allowed
mars 29, 2017 3:16:07 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFOS: Detected dialect: OSS
关键是我无法选中或取消选中“启用受保护...”框(请参阅下面的屏幕截图),因为我在工作网络上,所以我无法做我想做的事。
也许有人可以帮助我:)
【问题讨论】:
-
提供IE驱动的完整路径后可以试一试:
String driverPath = "C:\\Utility\\BrowserDrivers\\";System.setProperty("webdriver.ie.driver", driverPath+"IEDriverServer.exe"); -
现在有效了吗?
-
它没有解决我的问题...抱歉
-
和你遇到的问题一样吗?
-
是的,完全一样。只有一行:Listening on port 41586 which is different
标签: maven selenium internet-explorer junit