7

プロジェクトを通じてFirefox使用を自動化したいと思います。JavaSelenium WebDriver

使用したことがないため、Eclipse にインポートできるプロジェクトを作成するための適切なファイルをセットアップする方法に慣れていませんSeleniumMavenMaven pom.xml

http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-webdriverで、 Operaブラウザーの次の例を見つけました。

<?xml version="1.0" encoding="UTF-8"?>
<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>MySel20Proj</groupId>
    <artifactId>MySel20Proj</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.28.0</version>
        </dependency>
        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.opera</groupId>
                <artifactId>operadriver</artifactId>
                <version>1.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.seleniumhq.selenium</groupId>
                        <artifactId>selenium-remote-driver</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

pom.xmlこれを Firefox ブラウザに適用する方法を教えていただけないFirefox 17でしょうか。

4

4 に答える 4

4

selenium-java依存関係を使用すると、すべてのブラウザーのすべてのJavaバインディングを取得できます。だから、あなたはあなたがすでに持っているものからあなたのpomで何も変更する必要はありません。変更されるのは、ドライバー初期化コードだけです。これは、OperaDriverではなくdriver = new FirefoxDriver()です。

于 2013-02-19T14:44:34.900 に答える
3

以下は、 https : //github.com/Ardesco/selenium-standalone-server-pluginから取得した基本的な POMです。

<?xml version="1.0" encoding="UTF-8"?>
<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">

<groupId>com.lazerycode.selenium</groupId>
<artifactId>maven-template</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>

<name>Selenium Maven Template</name>
<description>A Maven Template For Selenium</description>
<url>http://www.lazerycode.com</url>

<licenses>
    <license>
        <name>Apache 2</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
        <comments>A business-friendly OSS license</comments>
    </license>
</licenses>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <selenium.version>2.45.0</selenium.version>
    <overwrite.binaries>false</overwrite.binaries>
    <browser>firefox</browser>
    <threads>1</threads>
    <remote>false</remote>
    <seleniumGridURL/>
    <platform/>
    <browserVersion/>
</properties>

<dependencies>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.2.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<profiles>
    <profile>
        <id>selenium-tests</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                    <version>2.3.2</version>
                </plugin>
                <plugin>
                    <groupId>com.lazerycode.selenium</groupId>
                    <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                    <version>1.0.7</version>
                    <configuration>
                        <rootStandaloneServerDirectory>${standalone.binary.root.folder}</rootStandaloneServerDirectory>
                        <downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>
                        <customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml</customRepositoryMap>
                        <overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>selenium</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.7.2</version>
                    <configuration>
                        <parallel>methods</parallel>
                        <threadCount>${threads}</threadCount>
                        <systemProperties>
                            <browser>${browser}</browser>
                            <screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
                            <remoteDriver>${remote}</remoteDriver>
                            <gridURL>${seleniumGridURL}</gridURL>
                            <desiredPlatform>${platform}</desiredPlatform>
                            <desiredBrowserVersion>${browserVersion}</desiredBrowserVersion>

                            <!--Set properties passed in by the driver binary downloader-->
                            <phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
                            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                            <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
                            <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
                        </systemProperties>
                        <includes>
                            <include>**/*WebDriver.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

この意志:

  • 必要なすべての Selenium ライブラリをダウンロードする
  • スタンドアロン ドライバー バイナリ (chromedriver、phantomJS など) をダウンロードします。
  • PhantomJSdriver ライブラリをダウンロードする
  • TestNG をテスト フレームワークとして追加する
  • 明確なテスト アサーションのために、すべての Hamcrest マッチャーを追加します ( https://code.google.com/p/hamcrest/wiki/Tutorialを参照) 。

元のリンクをクリックすると、基本的なプロジェクトのセットアップに移動し、POM 以外のものが必要な場合は、チェックアウトして実行することができます。

于 2015-04-11T09:49:30.993 に答える
1

Firefox 17 が 2.28.0 でサポートされていなかったことは知っていますが、Selenium プロジェクトのホームページを閲覧すると、新しい洞察が得られました。最新のリリースな2.30.0ので、これを更新してください。

   <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.28.0</version>
    </dependency>

これに:

 <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.30.0</version>
    </dependency>

きれいにして、もう一度やり直してください。うまくいけば、それは役に立ちます。ここでの一般的なアドバイスは次のとおりです。常に最新バージョンの Selenium を使用してください

于 2013-02-19T12:47:57.353 に答える