开发者

Running Selenium 2.0 Selenese tests through Google Chrome using Selenium-Maven plugin

I am trying to run through some Selenium 2.0 HTML tests through the selenium maven plugin (version 1.1) on Google Chrome (version 12.0.742.100) and I get t开发者_如何学运维he error, Cannot call method 'indexOf' of undefined, after trying to execute the Open Command.

After searching, it seems that we should be executing our chrome executable with the --disable-web-security parameter, which isn't easy to do with the Selenese goal. It looks like the plugin allows us to specify the file path for the chrome executable as a part of the parameter in the Selenium-Maven-plugin, but it doesn't allow me to append the --disable-web-security to the call. It will give out a maven build error if I try to do so.

What I tried to do is put the call in a batch file, and then point to the batch file in my POM, and that worked. However, what ends up happening is that the chrome browser starts up and doesn't go to the test runner, it stays on my home page.

My question here, is there anyway to get over the errors that I pointed through the Selenese tests in Chrome using the Selenium-Maven plugin? If not, what is the best way to approach this besides converting the tests to JUnits/TestNg tests.

Please see the snippet of my POM file below.

....
<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>
....

Thanks,

Juan


Try the desiredCapabilities - see here: http://code.google.com/p/selenium/wiki/ChromeDriver

So I would suggest you using something like this in your @BeforeClass function:

 @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 best way is to store chromedriver.exe in your maven /src subdirectory

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜