我正试图通过谷歌Chrome(12.0.742.100版)上的Selenium maven插件(1.1版)运行一些Selenium 2.0 HTML测试,但在尝试执行Open命令后,我得到了错误,无法调用未定义的方法'indexOf'。
搜索后,我们似乎应该使用--disable web security参数执行chrome可执行文件,这对于Selenese的目标来说并不容易。该插件似乎允许我们指定chrome可执行文件的文件路径,作为Selenium Maven插件中参数的一部分,但它不允许我在调用中附加--disable web security。如果我尝试这样做,它会发出一个maven构建错误。
我试图做的是将调用放在一个批处理文件中,然后指向POM中的批处理文件,这就成功了。然而,最终发生的是,chrome浏览器启动了,没有转到测试运行程序,而是停留在我的主页上。
我的问题是,有没有办法克服我在Chrome中使用SeleniumMaven插件进行Selenese测试时指出的错误?如果没有,除了将测试转换为JUnits/TestNg测试之外,最好的方法是什么。
请参阅下面我的POM文件的片段。
....
<properties>
<selenium.version>2.0b3</selenium.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>${selenium.version}</version>
<type>pom</type>
<exclusions>
<!-- prevent ant:ant versus org.apache.ant:ant collision -->
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<executions>
<execution>
<id>Run-googlechrome-Script</id>
<phase>integration-test</phase>
<goals>
<goal>selenese</goal>
</goals>
<configuration>
<browser>*googlechrome</browser>
<suite>src/test/selenium/html/TestSuite.html</suite>
<startURL>http://localhost:5555/</startURL>
<results>${project.build.directory}/results/googlechrome-smoke-results.html</results>
<port>5555</port>
<timeoutInSeconds>5000</timeoutInSeconds>
<multiWindow>true</multiWindow>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
....
谢谢,
Juan
尝试所需的功能-请参阅此处:http://code.google.com/p/selenium/wiki/ChromeDriver
所以我建议你在@BeforeClass函数中使用这样的东西:
@BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--disable-web-security"));
WebDriver driver = new ChromeDriver(capabilities);
BTW最好的方法是将chromedriver.exe存储在您的maven/src子目录