LoginSignup
3
4

More than 5 years have passed since last update.

Safariにselenium-webdriverを通してselenideで実行する

Last updated at Posted at 2017-01-17

はじめに

MacOSを再インストールしなおしたのでwebdriverも入れ直します。
ついでにjavaのテストフレームワークselenideから動作できるように設定して行きます。

動作環境

2017/01/17時点で以下の環境で実行しました
・MacOs Sierra
・safari 10.0
・Gradle 3.3
・IntelliJ IDEA

参考サイト

Safari 10 の WebDriver ネイティブサポート
Safari 10、WebDriverを搭載

導入

  1. webdriverをインストール
  2. Gradleにselenideを設定
  3. Javaでテストソースコーディング & テスト実行

webdriverをインストール

safari10より標準で入っている模様
だが下のステップを踏んでいく。

まずはsafariの「リモートオートメーションを許可する」をonにする。

スクリーンショット 2017-01-16 20.11.26.png

ターミナルより初回起動を実行する。
touchbar搭載機の場合はtouchIDでパスを入力しなくても良い。

コマンド
/usr/bin/safaridriver --port 0

build.gradle

build.gradle
buildscript {
    ext {
        // SpringBoot framework
        springBootVersion = "1.4.3.RELEASE"// 2016,1223

        // Others
        // Selenide
        selenideVersion = "4.2"// 2016,1226
        // Selenium
        seleniumVersion = "3.0.1"// 2017,0117
    }
    repositories {
        jcenter()
    }
}
ext['selenium.version'] = '3.0.1'// 2017,0117
dependencies {

        // SpringBoot projects
        testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
        compile("org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion")
        compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")

        // Others
        // Selenide
        testCompile("com.codeborne:selenide:$selenideVersion")
        testCompile("org.seleniumhq.selenium:selenium-server:$seleniumVersion")
        // SafariDriver
        testCompile("org.seleniumhq.selenium:selenium-safari-driver:$seleniumVersion")

}

Springbootに組み込み、テスト実行

PageControllerSelenideTest.java
public class PageControllerSelenideTest {

    @BeforeClass
    public static void setUpClass() {

        // テスト対象アプリの起動
        WebApp.main(new String[]{""});
        Configuration.browser = WebDriverRunner.SAFARI;
    }
    @After
    public void tearDown() {
    }


    @AfterClass
    public static void tearDownClass() {
        WebDriverRunner.closeWebDriver();
    }

    @Test
    public void test() throws Exception {
        // Test対象画面をページオブジェクトパターンで実装
        ChoiceQuestionPage page = ChoiceQuestionPage.open();

        Selenide.screenshot("init");
    }
}

IntelliJから実行するとこんな感じでスクショ撮ってくれている
スクリーンショット 2017-01-17 21.21.56.png

苦労したこと

IntelliJの依存関係の中で、seleniumがひたすら古いバージョンを参照していてエラーが頻発していました。
spring-boot-starter-webをデフォルトで使用していると古いバージョンを引っ張ってしまうようです。
原因は下記ページを覗けばなんとなく伝わるかと思います。
spring-boot-dependencies
また、Safariのライブラリがselenideから除外されていたり、参考にするページがなかったりとひたすらtry&errorを踏んでいました。

ソースはこちら

MultiModule-Sudoku

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4