LoginSignup
3
1

More than 5 years have passed since last update.

Selenideをやってみる

Last updated at Posted at 2018-06-05

はじめに

Seleniumをやってみるの続きです。
Selenideとやらを動かしてみます。

Selenide公式: http://selenide.org/

Selenideとは

Seleniumの機能をラッパーしたブラウザによるUIテストツール

Mavenの設定ファイルの修正

  • pom.xmlに依存ライブラリを追記
pom.xml
<dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>selenide</artifactId>
    <version>4.12.1</version>
</dependency>

サンプルコードの作成

SelenideTest.java
package com.example;

import org.junit.Test;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.WebDriverRunner;

public class SelenideTest {

    @Test
    public void isSelenidePage () {
        Configuration.browser = WebDriverRunner.CHROME;
        final String PATH = "(chromedriverの格納されている場所)";
        System.setProperty("webdriver.gecko.driver", PATH);

        Selenide.open("http://selenide.org");
        Selenide.$("div.short.wiki h3").shouldHave(Condition.text("What is Selenide?"));
        Selenide.$$(".quicklinks ul.gray-boxes li").shouldHaveSize(5);
    }

}
  • SelenideTest.javaを実行するとChromeブラウザを開いてSelenideの公式ページにアクセス後、テストを実行する

Selenideによるテストコードの作成

SelenideTest.java
package com.example;

import org.junit.Test;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.WebDriverRunner;

public class SelenideTest {

    @Test
    public void test () {
        Configuration.browser = WebDriverRunner.CHROME;
        final String PATH = "(chromedriverの格納されている場所)";
        System.setProperty("webdriver.gecko.driver", PATH);

        Selenide.open("http://localhost:8080/maven_sample/index.jsp");

        Selenide.$("h1").shouldHave(Condition.exactText("Fruits Shop"));

        ElementsCollection lists = Selenide.$$("li");

        lists.shouldHaveSize(3);

        lists.get(0).shouldHave(Condition.text("Apple"));
        lists.get(1).shouldHave(Condition.text("Banana"));
        lists.get(2).shouldHave(Condition.text("Cherry"));
    }

}

おわりに

なんとかSelenideを使えました。
Seleniumをちょっと簡単に使えるようになった感じですね、、
参考になれば幸いです。

以上、JUnitからSelenideまで単体テストツールを動かしてみました。

まとめ

3
1
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
1