SlideShare a Scribd company logo
1 of 147
Download to read offline
ブラウザテストを
       自動化することにした  
      〜~TestNGとSeleniumでやってみる〜~

        #kansumiB3             阪田  浩一
                               フリュー株式会社
                               ソーシャルネットワーク事業部
                                                1
                Developers Summit 2012
2012年9月15日土曜日                                       1
みなさん、
                こんにちは
                こんにちは!!

                                          2
                 Developers Summit 2012
2012年9月15日土曜日                                 2
まずは


                                         3
                Developers Summit 2012
2012年9月15日土曜日                                3
安心と定番の


                                          4
                 Developers Summit 2012
2012年9月15日土曜日                                 4
自己紹介から。


                                           5
                  Developers Summit 2012
2012年9月15日土曜日                                  5
阪田  浩一
                      (さかた  こういち)




                                         6
                Developers Summit 2012
2012年9月15日土曜日                                6
「すごくない」
                プログラマです。

                                           7
                  Developers Summit 2012
2012年9月15日土曜日                                  7
Twitter:  @jyukutyo
         はてな:  jyukutyo
          「じゅくちょー」

                                         8
                Developers Summit 2012
2012年9月15日土曜日                                8
神戸出身
                大阪在住

                                         9
                Developers Summit 2012
2012年9月15日土曜日                                9
フリュー株式会社
      ソーシャルネットワーク
          事業部

                                         10
                Developers Summit 2012
2012年9月15日土曜日                                 10
プリントシール機と
        連動した画像SNSを
         作っています。

                                         11
                Developers Summit 2012
2012年9月15日土曜日                                 11
半年前まで
     SIの世界(客先常駐)に
         いました。

                                         12
                Developers Summit 2012
2012年9月15日土曜日                                 12
こんな本とか記事
             書いています。

                                         13
                Developers Summit 2012
2012年9月15日土曜日                                 13
日本語版                            韓国語版




                                                       14
                       Developers Summit 2012
2012年9月15日土曜日                                               14
@IT連載
        次世代テスティングフレームワーク
                  「TestNG」
       http://www.atmarkit.co.jp/fjava/
      rensai4/testng01/testng01_1.html



                                          15
                 Developers Summit 2012
2012年9月15日土曜日                                  15
関西Javaエンジニアの会
        (関ジャバ)


                                         16
                Developers Summit 2012
2012年9月15日土曜日                                 16
というコミュニティ
                  やってます。


                                           17
                  Developers Summit 2012
2012年9月15日土曜日                                   17
では


                                         18
                Developers Summit 2012
2012年9月15日土曜日                                 18
今日のゴール


                                          Original Update by opofatticus
                                                                           19
                 Developers Summit 2012
2012年9月15日土曜日                                                                   19
ブラウザでのテストを
    全部人間がやる必要って
      あるのかなあ…

                                         20
                Developers Summit 2012
2012年9月15日土曜日                                 20
という疑問を
                持ってもらうこと!


                                           21
                  Developers Summit 2012
2012年9月15日土曜日                                   21
このセッションで
                ターゲットとする人

                                           Original Update by ##Erika**
                                                                          22
                  Developers Summit 2012
2012年9月15日土曜日                                                                  22
Webアプリケーション開発に関係します!
       JUnitでテストコード書いてます!
       結合テストとかめんどくさすぎ!
       JenkinsとかCIツールでビルドしています!
       TestNG?なにそれ?おいしいの?

                                         23
                Developers Summit 2012
2012年9月15日土曜日                                 23
どれかに
                当てはまれば
                  OK!

                                          24
                 Developers Summit 2012
2012年9月15日土曜日                                  24
 では
                本題スタート!


                                          25
                 Developers Summit 2012
2012年9月15日土曜日                                  25
結合テスト(機能テスト)
         フェーズ…

                                         Original Update by Phillie Casablanca
                                                                       26
                Developers Summit 2012
2012年9月15日土曜日                                                               26
IEとExcelとクリックの
         日々が続いていた…


                                         27
                Developers Summit 2012
2012年9月15日土曜日                                 27
あ〜~めんどくせぇ
                クリックするのも
                 面倒でいやだ

                                           28
                  Developers Summit 2012
2012年9月15日土曜日                                   28
そうだ!
       ブラウザでのテストも
       ユニットテストみたいに
        自動化できれば…!
                                         29
                Developers Summit 2012
2012年9月15日土曜日                                 29
ブラウザテスト自動化…


                                         30
                Developers Summit 2012
2012年9月15日土曜日                                 30
よし、全力でいくか…


                                         31
                Developers Summit 2012
2012年9月15日土曜日                                 31
ブラウザでの
      操作をコーディングする
        方法がある。

                                         32
                Developers Summit 2012
2012年9月15日土曜日                                 32
そのためのツール
                 「Selenium」


                                            33
                   Developers Summit 2012
2012年9月15日土曜日                                    33
「Selenium」には
                3つのものがある。


                                            34
                   Developers Summit 2012
2012年9月15日土曜日                                    34
Firefoxアドオンで
           ブラウザでの操作を
               記録する
           「Selenium  IDE」
                                         35
                Developers Summit 2012
2012年9月15日土曜日                                 35
ブラウザでの操作を
       コーディングする
   「Selenium  WebDriver」
                (Remote  Controlの後継)


                                              36
                     Developers Summit 2012
2012年9月15日土曜日                                      36
複数ブラウザでの
         テストを複数マシンで
            並列実行する
          「Selenium  Grid」
                                         37
                Developers Summit 2012
2012年9月15日土曜日                                 37
WebDriverを使う…


                                         38
                Developers Summit 2012
2012年9月15日土曜日                                 38
WebDriverなら、
           Java、C#、Python、
            Ruby、PHP、Perl
            で書けるんだぜ…
                                         39
                Developers Summit 2012
2012年9月15日土曜日                                 39
今回テスト対象とする
         アプリはこれだ!


                                         40
                Developers Summit 2012
2012年9月15日土曜日                                 40
41
                Developers Summit 2012
2012年9月15日土曜日                                 41
41
                Developers Summit 2012
2012年9月15日土曜日                                 41
さて、


                                         42
                Developers Summit 2012
2012年9月15日土曜日                                 42
ブラウザでのテストって、
       基本こうだよな…


                                         43
                Developers Summit 2012
2012年9月15日土曜日                                 43
1.とある画面にアクセスして、
    2.入力項目になんか入れて、
    3.サブミットしたら、
    4.画面が再描画される。


                                         44
                Developers Summit 2012
2012年9月15日土曜日                                 44
これをWebDriverの
           コードにすると、


                                         45
                Developers Summit 2012
2012年9月15日土曜日                                 45
とある画面にアクセスして、
 // ブラウザを表すオブジェクトを生成する
 WebDriver driver = new FirefoxDriver();

 // URLにアクセスする
 driver.get("http://localhost:8080/login.html");




                                             46
                  Developers Summit 2012
2012年9月15日土曜日                                      46
入力項目になんか入れて、
 // 画面上の項目を取得する
 // HTMLのname属性で要素を指定する
 WebElement userId =
     driver.findElement(By.name("j_username"));
 WebElement password =
     driver.findElement(By.name("j_password"));

 // テキストボックスに値を入力する
 userId.sendKeys("admin");
 password.sendKeys("spring");


                                              47
                   Developers Summit 2012
2012年9月15日土曜日                                      47
サブミットしたら、
 // XPathを使って要素を取得することもできる
 WebElement loginButton =
     driver.findElement(
       By.xpath("//input[@type='submit']"));

 // ボタンをクリックして、サブミットする
 loginButton.click();




                                               48
                   Developers Summit 2012
2012年9月15日土曜日                                       48
画面が再描画される。
 // ログインが成功したら、商品一覧画面に遷移する
 // HTMLのタイトル文字列で遷移を確認することにする
 Assert.assertEquals(driver.getTitle(),
      "マスタ管理 - 商品一覧画面");




                                           49
                  Developers Summit 2012
2012年9月15日土曜日                                   49
簡単じゃないか…


                                           50
                  Developers Summit 2012
2012年9月15日土曜日                                   50
ブラウザも
          Firefoxだけじゃない


                                         51
                Developers Summit 2012
2012年9月15日土曜日                                 51
FirefoxDriver
       InternetExplorerDriver
       ChromeDriver
       OperaDriver
       HtmlUnitDriver
       AndroidDriver
       iPhoneDriver
                                            52
                   Developers Summit 2012
2012年9月15日土曜日                                    52
そして、


                                         53
                Developers Summit 2012
2012年9月15日土曜日                                 53
画面上の
       要素を取得する方法は
         いくつもある。

                                         54
                Developers Summit 2012
2012年9月15日土曜日                                 54
要素を取得する方法まとめ
   ID属性で取得する         By.id("item_name")

   クラス名で取得する         By.className("required")

   タグ名で取得する          By.tagName("div")

   name属性で取得する       By.name("item_name")

   リンクのテキストで取得する     By.linkText("add item")

   CSSセレクタで取得する      By.cssSelector("#food span")

   XPathで取得する        By.xpath("//input")
                     (WebElement) ((JavascriptExecutor)driver).
   jQueryで取得する                    executeScript("return $('.cheese')")
                                                                    55
                   Developers Summit 2012
2012年9月15日土曜日                                                            55
話を戻して。


                                          56
                 Developers Summit 2012
2012年9月15日土曜日                                  56
このテストは
           うまくいかなかった。


                                         57
                Developers Summit 2012
2012年9月15日土曜日                                 57
同じテストでも
                成功するときと
                失敗するときが
                  あった!
                                          58
                 Developers Summit 2012
2012年9月15日土曜日                                  58
なぜだ!


                                         59
                Developers Summit 2012
2012年9月15日土曜日                                 59
ブラウザだからさ…


                                         60
                Developers Summit 2012
2012年9月15日土曜日                                 60
遷移より早く、assertが実行される
 // ボタンをクリックして、サブミットする
 loginButton.click();

 // ログインが成功したら、商品一覧画面に遷移する
 // HTMLのタイトル文字列で遷移を確認することにする
 Assert.assertEquals(driver.getTitle(),
      "マスタ管理 - 商品一覧画面");




                                           61
                  Developers Summit 2012
2012年9月15日土曜日                                   61
実際の画面遷移より早く、
       assertが
     実行されてしまう!

                                         62
                Developers Summit 2012
2012年9月15日土曜日                                 62
そんなこともあろうかと!


                                         63
                Developers Summit 2012
2012年9月15日土曜日                                 63
タイムアウトを設定して、待つ
 // ボタンをクリックして、サブミットする
 loginButton.click();

 // 3秒を超えたら、TimeoutExceptionが発生する
 final int timeoutInSeconds = 3;
 WebDriverWait wait =
     new WebDriverWait(driver,timeoutInSeconds);
 wait.until(
     ExpectedConditions.titleIs(
       "マスタ管理 - 商品一覧画面"));


                                              64
                   Developers Summit 2012
2012年9月15日土曜日                                      64
完璧じゃないか…


                                           65
                  Developers Summit 2012
2012年9月15日土曜日                                   65
これだけじゃダメだ!


                                         66
                Developers Summit 2012
2012年9月15日土曜日                                 66
今回のテスト対象アプリを
    思い出してみよう。


                                         67
                Developers Summit 2012
2012年9月15日土曜日                                 67
商品追加画面に
           ファイルアップロード
            あるんですけど…

                                         68
                Developers Summit 2012
2012年9月15日土曜日                                 68
できます!


                                         69
                Developers Summit 2012
2012年9月15日土曜日                                 69
ファイルをアップロードする
 // <INPUT type="file">の要素を取得する
 WebElement file =
     driver.findElement(By.id("fileUpload"));

 // アップロードするファイルのパスを渡す
 file.sendKeys("/home/jyukutyo/duke.jpeg");




                                                70
                   Developers Summit 2012
2012年9月15日土曜日                                        70
商品削除画面に
     JavaScriptのダイアログ
        あるんですけど…

                                         71
                Developers Summit 2012
2012年9月15日土曜日                                 71
できます!


                                         72
                Developers Summit 2012
2012年9月15日土曜日                                 72
JavaScriptのアラートやダイアログを制御する
 button.click();

 // アラート(ダイアログ)に制御を移す
 Alert alert = driver.switchTo().alert();

 // OKならaccept()、キャンセルならdismiss()を呼ぶ
 alert.accept();




                                            73
                   Developers Summit 2012
2012年9月15日土曜日                                    73
ふう。
       これで問題は解決し…


                                         74
                Developers Summit 2012
2012年9月15日土曜日                                 74
まだ終わっちゃいない!


                                         75
                Developers Summit 2012
2012年9月15日土曜日                                 75
いわゆる結合テストには
      あの仕事がある…


                                         76
                Developers Summit 2012
2012年9月15日土曜日                                 76
エビデンス
                                         77
                Developers Summit 2012
2012年9月15日土曜日                                 77
Excelに
           スクリーンショットを
             貼るお仕事。

                                         78
                Developers Summit 2012
2012年9月15日土曜日                                 78
Seleniumなら、


                                            79
                   Developers Summit 2012
2012年9月15日土曜日                                    79
スクリーンショット
   (キャプチャ、ハードコピー)
       を撮れます!

                                         80
                Developers Summit 2012
2012年9月15日土曜日                                 80
スクリーンショットを撮る
 // スクリーンショットを撮る
 File file = ((TakesScreenshot)
     driver).getScreenshotAs(OutputType.FILE);

 // ファイルとして保存する
 FileUtils.copyFile(file, new File("/tmp/" +
     method.getName() + ".png"));




                                                 81
                   Developers Summit 2012
2012年9月15日土曜日                                         81
これでブラウザ操作を
          自動化できた。


                                         82
                Developers Summit 2012
2012年9月15日土曜日                                 82
さあJUnitで
                テストコードを…


                                           83
                  Developers Summit 2012
2012年9月15日土曜日                                   83
待て  あわてるな


                                           84
                  Developers Summit 2012
2012年9月15日土曜日                                   84
こういうものもある


                                           85
                  Developers Summit 2012
2012年9月15日土曜日                                   85
TestNG


                                         86
                Developers Summit 2012
2012年9月15日土曜日                                 86
JUnitと同じく
                 テスティング
                フレームワーク

                                           87
                  Developers Summit 2012
2012年9月15日土曜日                                   87
なぜ「TestNG」か


                                            88
                   Developers Summit 2012
2012年9月15日土曜日                                    88
XMLファイルにテスト対象を定義できる
       前後処理のタイミングが豊富である
       テストをグループ化できる
       テスト間に依存関係を定義できる


                                         89
                Developers Summit 2012
2012年9月15日土曜日                                 89
XMLファイルにテスト対象を定義できる
 <!DOCTYPE suite SYSTEM "http://testng.org/
   testng-1.0.dtd" >

 <suite name="Suite" verbose="2">
     <test name="all" >
          <packages>
              <package name="test" />
          </packages>
     </test>
 </suite>




                                              90
                   Developers Summit 2012
2012年9月15日土曜日                                      90
実行するテストを
                 選択できる


                                           91
                  Developers Summit 2012
2012年9月15日土曜日                                   91
TestNGの概念
                              Suite
                               Test
                Test Class                  Test Class
            Test       Test             Test       Test
           Method     Method           Method     Method


                               Test
                Test Class                  Test Class
            Test       Test             Test       Test
           Method     Method           Method     Method

                                                           92
                        Developers Summit 2012
2012年9月15日土曜日                                                   92
前後処理のタイミングが豊富である
   @BeforeSuite   <suite>要素に含まれる全テストメソッドを呼び出す前
   @AfterSuite    にアノテーションを付けたメソッドを実行する

   @BeforeTest    <test>要素に含まれる全テストメソッドを呼び出す前に
   @AfterTest     アノテーションを付けたメソッドを実行する

   @BeforeGroups そのグループにある全テストメソッドを呼び出す前にア
   @AfterGroups  ノテーションを付けたメソッドを実行する

   @BeforeClass   そのクラスにある全テストメソッドを呼び出す前後にアノ
   @AfterClass    テーションを付けたメソッドを実行する

   @BeforeMethod そのクラスにある各テストメソッドを呼び出す前後にアノ
   @AfterMethod  テーションを付けたメソッドを実行する
                                                 93
                     Developers Summit 2012
2012年9月15日土曜日                                         93
なぜタイミングが多いと
         いいの?


                                         94
                Developers Summit 2012
2012年9月15日土曜日                                 94
たとえば、


                                         95
                Developers Summit 2012
2012年9月15日土曜日                                 95
このコードは重い



 // ブラウザを表すオブジェクトを生成する
 WebDriver driver = new FirefoxDriver();




                                           96
                  Developers Summit 2012
2012年9月15日土曜日                                   96
Suiteの前に1回だけ
   インスタンスを生成させる


                                         97
                Developers Summit 2012
2012年9月15日土曜日                                 97
テスト実行時間が
                  短くできる


                                           98
                  Developers Summit 2012
2012年9月15日土曜日                                   98
テストをグループ化して
      最低限のテストだけを
        コミットビルドで
          実行し、
                                         99
                Developers Summit 2012
2012年9月15日土曜日                                 99
重いテストは
                定期ビルド
                で実行する

                                          100
                 Developers Summit 2012
2012年9月15日土曜日                                   100
依存関係を設定し、
   前提テストが失敗すれば、
     後続のテストを
      スキップする
                                         101
                Developers Summit 2012
2012年9月15日土曜日                                  101
他にも、
       複数スレッドでテストを
           実行し、
        テスト実行時間を
         短くできたり…
                                         102
                Developers Summit 2012
2012年9月15日土曜日                                  102
そして、
        こういうテストコードが
            できた

                                         103
                Developers Summit 2012
2012年9月15日土曜日                                  103
protected static WebDriver driver;

 @BeforeSuite
 @Parameters({"browser"})
 public static void createDriver(
   @Optional("firefox") String browser) {
     if ("firefox".equals(browser)) {
         driver = new FirefoxDriver();
         return;
     }
     if ("safari".equals(browser)) {
         driver = new SafariDriver();
         return;
     }
     if ("unit".equals(browser)) {
         driver = new HtmlUnitDriver();
         return;
     }
 }                                          104
                  Developers Summit 2012
2012年9月15日土曜日                                     104
@BeforeMethod
 public void toLoginPage() {
    driver.get(
      "http://localhost:8080/login.html");
 }




                                             105
                  Developers Summit 2012
2012年9月15日土曜日                                      105
@Test
 public void ログインする() {
     WebElement userId =
      driver.findElement(By.name("j_username"));
 ...(中略)...
       userId.sendKeys("admin");
       password.sendKeys("spring");
       loginButton.click();

       final int timeoutInSeconds = 3;
       WebDriverWait wait = new
        WebDriverWait(driver, timeoutInSeconds);
       wait.until(
        ExpectedConditions.titleIs("商品一覧画面"));
 }

                                             106
                    Developers Summit 2012
2012年9月15日土曜日                                      106
@AfterSuite
 public static void closeDriver() {
    driver.quit();
 }




                                           107
                  Developers Summit 2012
2012年9月15日土曜日                                    107
テストコードを
                実行してみる


                                          108
                 Developers Summit 2012
2012年9月15日土曜日                                   108
109
                Developers Summit 2012
2012年9月15日土曜日                                  109
109
                Developers Summit 2012
2012年9月15日土曜日                                  109
まだだ。
                まだ終わらんよ!


                                           110
                  Developers Summit 2012
2012年9月15日土曜日                                    110
クロスブラウザ


                                          111
                 Developers Summit 2012
2012年9月15日土曜日                                   111
Driverインスタンスを
            変えればいい


                                         112
                Developers Summit 2012
2012年9月15日土曜日                                  112
マルチプラットフォーム
            ✕
         クロスブラウザ

                                         113
                Developers Summit 2012
2012年9月15日土曜日                                  113
WindowsのIEと
                OS  XのSafariで
                動作確認とか…

                                            114
                   Developers Summit 2012
2012年9月15日土曜日                                     114
こんなこともあろうかと


                                         115
                Developers Summit 2012
2012年9月15日土曜日                                  115
複数ブラウザでの
         テストを複数マシンで
            並列実行する
          「Selenium  Grid」
                                         116
                Developers Summit 2012
2012年9月15日土曜日                                  116
Test Code


    Selenium
                               Hub
     Grid


                Node          Node               Node




          Browser          Browser              Browser
                                                          117
                       Developers Summit 2012
2012年9月15日土曜日                                                   117
使い方は簡単。


                                          118
                 Developers Summit 2012
2012年9月15日土曜日                                   118
JARをダウンロードして起動するだけ!
 // start Hub
 java -jar selenium-server-standalone-2.25.0.jar -hub

 // start Node
 java -jar selenium-server-standalone-2.25.0.jar -role
 node -hub http://hubserver:4444/grid/register




                                                         119
                      Developers Summit 2012
2012年9月15日土曜日                                                  119
テストコードを少し変える
 // 要求する実行環境。
 // ブラウザのバージョンなども指定できる。
 DesiredCapabilities capability =
                DesiredCapabilities.firefox();

 // RemoteWebDriverというドライバを使う。
 // 要求を満たすブラウザがNodeから選択される。
 driver = new RemoteWebDriver(
   new URL(
     "http://hubserver:4444/wd/hub"),
     capability);
                                             120
                   Developers Summit 2012
2012年9月15日土曜日                                      120
テストコードを少し変える
 // RemoteWebDriverはTakesScreenshotを実装していない。
 // スクリーンショットを撮れるRemoteWebDriverの実装であれば、
 // AugmenterがTakesScreenshotインタフェースを追加する。
 WebDriver augmentedDriver =
               new Augmenter().augment(driver);
 File file = ((TakesScreenshot)augmentedDriver).
               getScreenshotAs(OutputType.FILE);
 FileUtils.copyFile(file, new File(
        "/tmp/" + method.getName() + ".png"));




                                               121
                   Developers Summit 2012
2012年9月15日土曜日                                        121
そして、


                                         122
                Developers Summit 2012
2012年9月15日土曜日                                  122
Selenium  Gridを
                    使うとき、


                                             123
                    Developers Summit 2012
2012年9月15日土曜日                                      123
JenkinsとSelenium  
            Pluginを使うと
                便利!

                                         124
                Developers Summit 2012
2012年9月15日土曜日                                  124
Jenkinsとは




                                           125
                  Developers Summit 2012
2012年9月15日土曜日                                    125
CIツール
        (Continuous  Integration)



                                         126
                Developers Summit 2012
2012年9月15日土曜日                                  126
基本的な使い方としては、



                                         127
                Developers Summit 2012
2012年9月15日土曜日                                  127
SCMへのコミットをフックにして
     最新のソースコードを取得し、
      ビルドやテストを実行する
        アプリケーション

                                         128
                Developers Summit 2012
2012年9月15日土曜日                                  128
本題と外れるので、
                詳細は省略します。



                                           129
                  Developers Summit 2012
2012年9月15日土曜日                                    129
で、Selenium  Pluginを使って
         Jenkinsでテストを
            実行させる


                                         130
                Developers Summit 2012
2012年9月15日土曜日                                  130
Selenium  Pluginが便利!

       JenkinsサーバがHubになります!
       Hubを自動起動してくれます!
       JenkinsのスレーブをNodeとして
        自動的にHubに登録してくれます!


                                         131
                Developers Summit 2012
2012年9月15日土曜日                                  131
Jenkinsサーバ(マスタ)が
       GNU/Linuxで
          あっても

                                         132
                Developers Summit 2012
2012年9月15日土曜日                                  132
余ったWindowsマシンを
    Jenkinsスレーブにして


                                         133
                Developers Summit 2012
2012年9月15日土曜日                                  133
IEでのテストを
                 実行させよう!


                                           134
                  Developers Summit 2012
2012年9月15日土曜日                                    134
デモ


                                         135
                Developers Summit 2012
2012年9月15日土曜日                                  135
役割

                 Jenkinsのマスタサーバ。
   OS X          Selenium  GridのHub。
                 Firefoxでのテストを実施する。


                 Jenkinsのスレーブ。
   VirtualBox上
                 Selenium  GridのNode。
   のWindows XP
                 IEでのテストを実施する。
                                          136
                 Developers Summit 2012
2012年9月15日土曜日                                   136
137
                Developers Summit 2012
2012年9月15日土曜日                                  137
137
                Developers Summit 2012
2012年9月15日土曜日                                  137
JenkinsとSelenium  Gridの組み合わせは、
 川口さんの記事を参考にいたしました。




                                         138
                Developers Summit 2012
2012年9月15日土曜日                                  138
まとめ


                                         139
                Developers Summit 2012
2012年9月15日土曜日                                  139
Jenkinsサイコー!(違


                                         140
                Developers Summit 2012
2012年9月15日土曜日                                  140
ブラウザテストも
                 自動化できる
                 (部分がある)

                                           141
                  Developers Summit 2012
2012年9月15日土曜日                                    141
めんどくさいことは
            できる限りマシンに
              やらせよう

                                         142
                Developers Summit 2012
2012年9月15日土曜日                                  142
今日のソースコード
             Github
       https://github.com/jyukutyo/devsumi-­kansai2012
    https://github.com/jyukutyo/devsumi-­kansai2012-­Grid




                                                       143
                       Developers Summit 2012
2012年9月15日土曜日                                                143
ご清聴
     ありがとうございました!


                                         144
                Developers Summit 2012
2012年9月15日土曜日                                  144

More Related Content

Similar to デブサミ関西2012 B-3

アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~Dai FUJIHARA
 
アジャイルリーダーシップと組織改革
アジャイルリーダーシップと組織改革アジャイルリーダーシップと組織改革
アジャイルリーダーシップと組織改革Rakuten Group, Inc.
 
HOTATE (Developers Summit 2012)
HOTATE (Developers Summit 2012)HOTATE (Developers Summit 2012)
HOTATE (Developers Summit 2012)Yoshihiro Iwanaga
 
ふつうのプログラマの自分戦略
ふつうのプログラマの自分戦略ふつうのプログラマの自分戦略
ふつうのプログラマの自分戦略irof N
 
20120915 近畿大学 it交流勉強会(公開用)
20120915 近畿大学 it交流勉強会(公開用)20120915 近畿大学 it交流勉強会(公開用)
20120915 近畿大学 it交流勉強会(公開用)Shinya Sato
 
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~Takao Oyobe
 
The World Is Mine - Developers Summit 2012への道
The World Is Mine - Developers Summit 2012への道The World Is Mine - Developers Summit 2012への道
The World Is Mine - Developers Summit 2012への道Dai FUJIHARA
 
WordPress のいま
WordPress のいまWordPress のいま
WordPress のいまNaoko Takano
 
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)Rakuten Group, Inc.
 
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグ
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグアジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグ
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグDai FUJIHARA
 
第7回ゆるふわ勉強会
第7回ゆるふわ勉強会第7回ゆるふわ勉強会
第7回ゆるふわ勉強会horike37
 
How to change our world ~楽天の開発現場からのアジャイル改善事例~
How to change our world ~楽天の開発現場からのアジャイル改善事例~How to change our world ~楽天の開発現場からのアジャイル改善事例~
How to change our world ~楽天の開発現場からのアジャイル改善事例~Rakuten Group, Inc.
 
WordPress+不動産プラグイン活用例
WordPress+不動産プラグイン活用例WordPress+不動産プラグイン活用例
WordPress+不動産プラグイン活用例加藤 貴一
 
テスト駆動開発の進化
テスト駆動開発の進化テスト駆動開発の進化
テスト駆動開発の進化Yukei Wachi
 
smartphone test (know how & tools)
smartphone test (know how & tools)smartphone test (know how & tools)
smartphone test (know how & tools)Yukio Andoh
 
Online programming examination
Online programming examinationOnline programming examination
Online programming examinationMocke Tech
 
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)Developers Summit
 
プロ文.com 勉強会 Phase 1
プロ文.com 勉強会 Phase 1プロ文.com 勉強会 Phase 1
プロ文.com 勉強会 Phase 1Hiroki Toyokawa
 

Similar to デブサミ関西2012 B-3 (20)

アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~
 
アジャイルリーダーシップと組織改革
アジャイルリーダーシップと組織改革アジャイルリーダーシップと組織改革
アジャイルリーダーシップと組織改革
 
HOTATE (Developers Summit 2012)
HOTATE (Developers Summit 2012)HOTATE (Developers Summit 2012)
HOTATE (Developers Summit 2012)
 
ふつうのプログラマの自分戦略
ふつうのプログラマの自分戦略ふつうのプログラマの自分戦略
ふつうのプログラマの自分戦略
 
20120915 近畿大学 it交流勉強会(公開用)
20120915 近畿大学 it交流勉強会(公開用)20120915 近畿大学 it交流勉強会(公開用)
20120915 近畿大学 it交流勉強会(公開用)
 
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~
20121021 Lean!! Lean!! Lean!! ~DevLOVEと現場と私~
 
The World Is Mine - Developers Summit 2012への道
The World Is Mine - Developers Summit 2012への道The World Is Mine - Developers Summit 2012への道
The World Is Mine - Developers Summit 2012への道
 
WordPress のいま
WordPress のいまWordPress のいま
WordPress のいま
 
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)
アジャイルリーダーシップと組織改革 (アジャイルサムライ横浜道場)
 
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグ
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグアジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグ
アジャイルリーダーシップと組織改革 ~楽天のアジャイル開発というリアル~ エピローグ
 
第7回ゆるふわ勉強会
第7回ゆるふわ勉強会第7回ゆるふわ勉強会
第7回ゆるふわ勉強会
 
How to change our world ~楽天の開発現場からのアジャイル改善事例~
How to change our world ~楽天の開発現場からのアジャイル改善事例~How to change our world ~楽天の開発現場からのアジャイル改善事例~
How to change our world ~楽天の開発現場からのアジャイル改善事例~
 
WordPress+不動産プラグイン活用例
WordPress+不動産プラグイン活用例WordPress+不動産プラグイン活用例
WordPress+不動産プラグイン活用例
 
テスト駆動開発の進化
テスト駆動開発の進化テスト駆動開発の進化
テスト駆動開発の進化
 
smartphone test (know how & tools)
smartphone test (know how & tools)smartphone test (know how & tools)
smartphone test (know how & tools)
 
Online programming examination
Online programming examinationOnline programming examination
Online programming examination
 
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)
夏サミ2013 基調講演 「DevOpsは開発現場とビジネスの間に何を生むか?」(新野淳一氏)
 
プロ文.com 勉強会 Phase 1
プロ文.com 勉強会 Phase 1プロ文.com 勉強会 Phase 1
プロ文.com 勉強会 Phase 1
 
Osc2012tokyo timing
Osc2012tokyo timingOsc2012tokyo timing
Osc2012tokyo timing
 
Devsumi2013 gunta 2_pdf
Devsumi2013 gunta 2_pdfDevsumi2013 gunta 2_pdf
Devsumi2013 gunta 2_pdf
 

More from Koichi Sakata

Introduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMIntroduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMKoichi Sakata
 
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Koichi Sakata
 
Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Koichi Sakata
 
Introduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageIntroduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageKoichi Sakata
 
Introduction to GraalVM
Introduction to GraalVMIntroduction to GraalVM
Introduction to GraalVMKoichi Sakata
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうKoichi Sakata
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyKoichi Sakata
 
Great Ideas in GraalVM
Great Ideas in GraalVMGreat Ideas in GraalVM
Great Ideas in GraalVMKoichi Sakata
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Kanjava 201804 Java News
Kanjava 201804 Java NewsKanjava 201804 Java News
Kanjava 201804 Java NewsKoichi Sakata
 
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKoichi Sakata
 
from Java EE to Jakarta EE
from Java EE to Jakarta EEfrom Java EE to Jakarta EE
from Java EE to Jakarta EEKoichi Sakata
 
Java release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberJava release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberKoichi Sakata
 
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるJJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるKoichi Sakata
 
KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説Koichi Sakata
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたKoichi Sakata
 
“Purikura” culture in Japan and our web application architecture
“Purikura” culturein Japan andour web application architecture“Purikura” culturein Japan andour web application architecture
“Purikura” culture in Japan and our web application architectureKoichi Sakata
 
デブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったデブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったKoichi Sakata
 
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているJJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているKoichi Sakata
 
日本からJavaOneに行こう!
日本からJavaOneに行こう!日本からJavaOneに行こう!
日本からJavaOneに行こう!Koichi Sakata
 

More from Koichi Sakata (20)

Introduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVMIntroduction to JIT Compiler in JVM
Introduction to JIT Compiler in JVM
 
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
Guide to GraalVM (Oracle Groundbreakers APAC 2019 Tour in Tokyo)
 
Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)Guide to GraalVM (JJUG CCC 2019 Fall)
Guide to GraalVM (JJUG CCC 2019 Fall)
 
Introduction to GraalVM and Native Image
Introduction to GraalVM and Native ImageIntroduction to GraalVM and Native Image
Introduction to GraalVM and Native Image
 
Introduction to GraalVM
Introduction to GraalVMIntroduction to GraalVM
Introduction to GraalVM
 
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼうGraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
GraalVMで使われている、他言語をJVM上に実装する仕組みを学ぼう
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
 
Great Ideas in GraalVM
Great Ideas in GraalVMGreat Ideas in GraalVM
Great Ideas in GraalVM
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Kanjava 201804 Java News
Kanjava 201804 Java NewsKanjava 201804 Java News
Kanjava 201804 Java News
 
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性があるKanJava 201804 Career 思い込みから逃れた先には、可能性がある
KanJava 201804 Career 思い込みから逃れた先には、可能性がある
 
from Java EE to Jakarta EE
from Java EE to Jakarta EEfrom Java EE to Jakarta EE
from Java EE to Jakarta EE
 
Java release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project AmberJava release cadence has been changed and about Project Amber
Java release cadence has been changed and about Project Amber
 
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみるJJUG CCC 2017 Fall オレオレJVM言語を作ってみる
JJUG CCC 2017 Fall オレオレJVM言語を作ってみる
 
KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説KANJAVA PARTY 2017 前説
KANJAVA PARTY 2017 前説
 
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めたJJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
JJUG CCC 2017 Spring Seasar2からSpringへ移行した俺たちのアプリケーションがマイクロサービスアーキテクチャへ歩み始めた
 
“Purikura” culture in Japan and our web application architecture
“Purikura” culturein Japan andour web application architecture“Purikura” culturein Japan andour web application architecture
“Purikura” culture in Japan and our web application architecture
 
デブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わったデブサミ2017 Javaコミュニティ作ったら人生変わった
デブサミ2017 Javaコミュニティ作ったら人生変わった
 
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっているJJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
JJUG CCC 2016 fall バイトコードが君のトモダチになりたがっている
 
日本からJavaOneに行こう!
日本からJavaOneに行こう!日本からJavaOneに行こう!
日本からJavaOneに行こう!
 

デブサミ関西2012 B-3

  • 1. ブラウザテストを 自動化することにした   〜~TestNGとSeleniumでやってみる〜~ #kansumiB3 阪田  浩一 フリュー株式会社 ソーシャルネットワーク事業部 1 Developers Summit 2012 2012年9月15日土曜日 1
  • 2. みなさん、 こんにちは こんにちは!! 2 Developers Summit 2012 2012年9月15日土曜日 2
  • 3. まずは 3 Developers Summit 2012 2012年9月15日土曜日 3
  • 4. 安心と定番の 4 Developers Summit 2012 2012年9月15日土曜日 4
  • 5. 自己紹介から。 5 Developers Summit 2012 2012年9月15日土曜日 5
  • 6. 阪田  浩一 (さかた  こういち) 6 Developers Summit 2012 2012年9月15日土曜日 6
  • 7. 「すごくない」 プログラマです。 7 Developers Summit 2012 2012年9月15日土曜日 7
  • 8. Twitter:  @jyukutyo はてな:  jyukutyo 「じゅくちょー」 8 Developers Summit 2012 2012年9月15日土曜日 8
  • 9. 神戸出身 大阪在住 9 Developers Summit 2012 2012年9月15日土曜日 9
  • 10. フリュー株式会社 ソーシャルネットワーク 事業部 10 Developers Summit 2012 2012年9月15日土曜日 10
  • 11. プリントシール機と 連動した画像SNSを 作っています。 11 Developers Summit 2012 2012年9月15日土曜日 11
  • 12. 半年前まで SIの世界(客先常駐)に いました。 12 Developers Summit 2012 2012年9月15日土曜日 12
  • 13. こんな本とか記事 書いています。 13 Developers Summit 2012 2012年9月15日土曜日 13
  • 14. 日本語版 韓国語版 14 Developers Summit 2012 2012年9月15日土曜日 14
  • 15. @IT連載 次世代テスティングフレームワーク 「TestNG」 http://www.atmarkit.co.jp/fjava/ rensai4/testng01/testng01_1.html 15 Developers Summit 2012 2012年9月15日土曜日 15
  • 16. 関西Javaエンジニアの会 (関ジャバ) 16 Developers Summit 2012 2012年9月15日土曜日 16
  • 17. というコミュニティ やってます。 17 Developers Summit 2012 2012年9月15日土曜日 17
  • 18. では 18 Developers Summit 2012 2012年9月15日土曜日 18
  • 19. 今日のゴール Original Update by opofatticus 19 Developers Summit 2012 2012年9月15日土曜日 19
  • 20. ブラウザでのテストを 全部人間がやる必要って あるのかなあ… 20 Developers Summit 2012 2012年9月15日土曜日 20
  • 21. という疑問を 持ってもらうこと! 21 Developers Summit 2012 2012年9月15日土曜日 21
  • 22. このセッションで ターゲットとする人 Original Update by ##Erika** 22 Developers Summit 2012 2012年9月15日土曜日 22
  • 23. Webアプリケーション開発に関係します! JUnitでテストコード書いてます! 結合テストとかめんどくさすぎ! JenkinsとかCIツールでビルドしています! TestNG?なにそれ?おいしいの? 23 Developers Summit 2012 2012年9月15日土曜日 23
  • 24. どれかに 当てはまれば OK! 24 Developers Summit 2012 2012年9月15日土曜日 24
  • 25.  では 本題スタート! 25 Developers Summit 2012 2012年9月15日土曜日 25
  • 26. 結合テスト(機能テスト) フェーズ… Original Update by Phillie Casablanca 26 Developers Summit 2012 2012年9月15日土曜日 26
  • 27. IEとExcelとクリックの 日々が続いていた… 27 Developers Summit 2012 2012年9月15日土曜日 27
  • 28. あ〜~めんどくせぇ クリックするのも 面倒でいやだ 28 Developers Summit 2012 2012年9月15日土曜日 28
  • 29. そうだ! ブラウザでのテストも ユニットテストみたいに 自動化できれば…! 29 Developers Summit 2012 2012年9月15日土曜日 29
  • 30. ブラウザテスト自動化… 30 Developers Summit 2012 2012年9月15日土曜日 30
  • 31. よし、全力でいくか… 31 Developers Summit 2012 2012年9月15日土曜日 31
  • 32. ブラウザでの 操作をコーディングする 方法がある。 32 Developers Summit 2012 2012年9月15日土曜日 32
  • 33. そのためのツール 「Selenium」 33 Developers Summit 2012 2012年9月15日土曜日 33
  • 34. 「Selenium」には 3つのものがある。 34 Developers Summit 2012 2012年9月15日土曜日 34
  • 35. Firefoxアドオンで ブラウザでの操作を 記録する 「Selenium  IDE」 35 Developers Summit 2012 2012年9月15日土曜日 35
  • 36. ブラウザでの操作を コーディングする 「Selenium  WebDriver」 (Remote  Controlの後継) 36 Developers Summit 2012 2012年9月15日土曜日 36
  • 37. 複数ブラウザでの テストを複数マシンで 並列実行する 「Selenium  Grid」 37 Developers Summit 2012 2012年9月15日土曜日 37
  • 38. WebDriverを使う… 38 Developers Summit 2012 2012年9月15日土曜日 38
  • 39. WebDriverなら、 Java、C#、Python、 Ruby、PHP、Perl で書けるんだぜ… 39 Developers Summit 2012 2012年9月15日土曜日 39
  • 40. 今回テスト対象とする アプリはこれだ! 40 Developers Summit 2012 2012年9月15日土曜日 40
  • 41. 41 Developers Summit 2012 2012年9月15日土曜日 41
  • 42. 41 Developers Summit 2012 2012年9月15日土曜日 41
  • 43. さて、 42 Developers Summit 2012 2012年9月15日土曜日 42
  • 44. ブラウザでのテストって、 基本こうだよな… 43 Developers Summit 2012 2012年9月15日土曜日 43
  • 45. 1.とある画面にアクセスして、 2.入力項目になんか入れて、 3.サブミットしたら、 4.画面が再描画される。 44 Developers Summit 2012 2012年9月15日土曜日 44
  • 46. これをWebDriverの コードにすると、 45 Developers Summit 2012 2012年9月15日土曜日 45
  • 47. とある画面にアクセスして、 // ブラウザを表すオブジェクトを生成する WebDriver driver = new FirefoxDriver(); // URLにアクセスする driver.get("http://localhost:8080/login.html"); 46 Developers Summit 2012 2012年9月15日土曜日 46
  • 48. 入力項目になんか入れて、 // 画面上の項目を取得する // HTMLのname属性で要素を指定する WebElement userId = driver.findElement(By.name("j_username")); WebElement password = driver.findElement(By.name("j_password")); // テキストボックスに値を入力する userId.sendKeys("admin"); password.sendKeys("spring"); 47 Developers Summit 2012 2012年9月15日土曜日 47
  • 49. サブミットしたら、 // XPathを使って要素を取得することもできる WebElement loginButton = driver.findElement( By.xpath("//input[@type='submit']")); // ボタンをクリックして、サブミットする loginButton.click(); 48 Developers Summit 2012 2012年9月15日土曜日 48
  • 50. 画面が再描画される。 // ログインが成功したら、商品一覧画面に遷移する // HTMLのタイトル文字列で遷移を確認することにする Assert.assertEquals(driver.getTitle(), "マスタ管理 - 商品一覧画面"); 49 Developers Summit 2012 2012年9月15日土曜日 49
  • 51. 簡単じゃないか… 50 Developers Summit 2012 2012年9月15日土曜日 50
  • 52. ブラウザも Firefoxだけじゃない 51 Developers Summit 2012 2012年9月15日土曜日 51
  • 53. FirefoxDriver InternetExplorerDriver ChromeDriver OperaDriver HtmlUnitDriver AndroidDriver iPhoneDriver 52 Developers Summit 2012 2012年9月15日土曜日 52
  • 54. そして、 53 Developers Summit 2012 2012年9月15日土曜日 53
  • 55. 画面上の 要素を取得する方法は いくつもある。 54 Developers Summit 2012 2012年9月15日土曜日 54
  • 56. 要素を取得する方法まとめ ID属性で取得する By.id("item_name") クラス名で取得する By.className("required") タグ名で取得する By.tagName("div") name属性で取得する By.name("item_name") リンクのテキストで取得する By.linkText("add item") CSSセレクタで取得する By.cssSelector("#food span") XPathで取得する By.xpath("//input") (WebElement) ((JavascriptExecutor)driver). jQueryで取得する executeScript("return $('.cheese')") 55 Developers Summit 2012 2012年9月15日土曜日 55
  • 57. 話を戻して。 56 Developers Summit 2012 2012年9月15日土曜日 56
  • 58. このテストは うまくいかなかった。 57 Developers Summit 2012 2012年9月15日土曜日 57
  • 59. 同じテストでも 成功するときと 失敗するときが あった! 58 Developers Summit 2012 2012年9月15日土曜日 58
  • 60. なぜだ! 59 Developers Summit 2012 2012年9月15日土曜日 59
  • 61. ブラウザだからさ… 60 Developers Summit 2012 2012年9月15日土曜日 60
  • 62. 遷移より早く、assertが実行される // ボタンをクリックして、サブミットする loginButton.click(); // ログインが成功したら、商品一覧画面に遷移する // HTMLのタイトル文字列で遷移を確認することにする Assert.assertEquals(driver.getTitle(), "マスタ管理 - 商品一覧画面"); 61 Developers Summit 2012 2012年9月15日土曜日 61
  • 63. 実際の画面遷移より早く、 assertが 実行されてしまう! 62 Developers Summit 2012 2012年9月15日土曜日 62
  • 64. そんなこともあろうかと! 63 Developers Summit 2012 2012年9月15日土曜日 63
  • 65. タイムアウトを設定して、待つ // ボタンをクリックして、サブミットする loginButton.click(); // 3秒を超えたら、TimeoutExceptionが発生する final int timeoutInSeconds = 3; WebDriverWait wait = new WebDriverWait(driver,timeoutInSeconds); wait.until( ExpectedConditions.titleIs( "マスタ管理 - 商品一覧画面")); 64 Developers Summit 2012 2012年9月15日土曜日 64
  • 66. 完璧じゃないか… 65 Developers Summit 2012 2012年9月15日土曜日 65
  • 67. これだけじゃダメだ! 66 Developers Summit 2012 2012年9月15日土曜日 66
  • 68. 今回のテスト対象アプリを 思い出してみよう。 67 Developers Summit 2012 2012年9月15日土曜日 67
  • 69. 商品追加画面に ファイルアップロード あるんですけど… 68 Developers Summit 2012 2012年9月15日土曜日 68
  • 70. できます! 69 Developers Summit 2012 2012年9月15日土曜日 69
  • 71. ファイルをアップロードする // <INPUT type="file">の要素を取得する WebElement file = driver.findElement(By.id("fileUpload")); // アップロードするファイルのパスを渡す file.sendKeys("/home/jyukutyo/duke.jpeg"); 70 Developers Summit 2012 2012年9月15日土曜日 70
  • 72. 商品削除画面に JavaScriptのダイアログ あるんですけど… 71 Developers Summit 2012 2012年9月15日土曜日 71
  • 73. できます! 72 Developers Summit 2012 2012年9月15日土曜日 72
  • 74. JavaScriptのアラートやダイアログを制御する button.click(); // アラート(ダイアログ)に制御を移す Alert alert = driver.switchTo().alert(); // OKならaccept()、キャンセルならdismiss()を呼ぶ alert.accept(); 73 Developers Summit 2012 2012年9月15日土曜日 73
  • 75. ふう。 これで問題は解決し… 74 Developers Summit 2012 2012年9月15日土曜日 74
  • 76. まだ終わっちゃいない! 75 Developers Summit 2012 2012年9月15日土曜日 75
  • 77. いわゆる結合テストには あの仕事がある… 76 Developers Summit 2012 2012年9月15日土曜日 76
  • 78. エビデンス 77 Developers Summit 2012 2012年9月15日土曜日 77
  • 79. Excelに スクリーンショットを 貼るお仕事。 78 Developers Summit 2012 2012年9月15日土曜日 78
  • 80. Seleniumなら、 79 Developers Summit 2012 2012年9月15日土曜日 79
  • 81. スクリーンショット (キャプチャ、ハードコピー) を撮れます! 80 Developers Summit 2012 2012年9月15日土曜日 80
  • 82. スクリーンショットを撮る // スクリーンショットを撮る File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); // ファイルとして保存する FileUtils.copyFile(file, new File("/tmp/" + method.getName() + ".png")); 81 Developers Summit 2012 2012年9月15日土曜日 81
  • 83. これでブラウザ操作を 自動化できた。 82 Developers Summit 2012 2012年9月15日土曜日 82
  • 84. さあJUnitで テストコードを… 83 Developers Summit 2012 2012年9月15日土曜日 83
  • 85. 待て  あわてるな 84 Developers Summit 2012 2012年9月15日土曜日 84
  • 86. こういうものもある 85 Developers Summit 2012 2012年9月15日土曜日 85
  • 87. TestNG 86 Developers Summit 2012 2012年9月15日土曜日 86
  • 88. JUnitと同じく テスティング フレームワーク 87 Developers Summit 2012 2012年9月15日土曜日 87
  • 89. なぜ「TestNG」か 88 Developers Summit 2012 2012年9月15日土曜日 88
  • 90. XMLファイルにテスト対象を定義できる 前後処理のタイミングが豊富である テストをグループ化できる テスト間に依存関係を定義できる 89 Developers Summit 2012 2012年9月15日土曜日 89
  • 91. XMLファイルにテスト対象を定義できる <!DOCTYPE suite SYSTEM "http://testng.org/ testng-1.0.dtd" > <suite name="Suite" verbose="2"> <test name="all" > <packages> <package name="test" /> </packages> </test> </suite> 90 Developers Summit 2012 2012年9月15日土曜日 90
  • 92. 実行するテストを 選択できる 91 Developers Summit 2012 2012年9月15日土曜日 91
  • 93. TestNGの概念 Suite Test Test Class Test Class Test Test Test Test Method Method Method Method Test Test Class Test Class Test Test Test Test Method Method Method Method 92 Developers Summit 2012 2012年9月15日土曜日 92
  • 94. 前後処理のタイミングが豊富である @BeforeSuite <suite>要素に含まれる全テストメソッドを呼び出す前 @AfterSuite にアノテーションを付けたメソッドを実行する @BeforeTest <test>要素に含まれる全テストメソッドを呼び出す前に @AfterTest アノテーションを付けたメソッドを実行する @BeforeGroups そのグループにある全テストメソッドを呼び出す前にア @AfterGroups ノテーションを付けたメソッドを実行する @BeforeClass そのクラスにある全テストメソッドを呼び出す前後にアノ @AfterClass テーションを付けたメソッドを実行する @BeforeMethod そのクラスにある各テストメソッドを呼び出す前後にアノ @AfterMethod テーションを付けたメソッドを実行する 93 Developers Summit 2012 2012年9月15日土曜日 93
  • 95. なぜタイミングが多いと いいの? 94 Developers Summit 2012 2012年9月15日土曜日 94
  • 96. たとえば、 95 Developers Summit 2012 2012年9月15日土曜日 95
  • 97. このコードは重い // ブラウザを表すオブジェクトを生成する WebDriver driver = new FirefoxDriver(); 96 Developers Summit 2012 2012年9月15日土曜日 96
  • 98. Suiteの前に1回だけ インスタンスを生成させる 97 Developers Summit 2012 2012年9月15日土曜日 97
  • 99. テスト実行時間が 短くできる 98 Developers Summit 2012 2012年9月15日土曜日 98
  • 100. テストをグループ化して 最低限のテストだけを コミットビルドで 実行し、 99 Developers Summit 2012 2012年9月15日土曜日 99
  • 101. 重いテストは 定期ビルド で実行する 100 Developers Summit 2012 2012年9月15日土曜日 100
  • 102. 依存関係を設定し、 前提テストが失敗すれば、 後続のテストを スキップする 101 Developers Summit 2012 2012年9月15日土曜日 101
  • 103. 他にも、 複数スレッドでテストを 実行し、 テスト実行時間を 短くできたり… 102 Developers Summit 2012 2012年9月15日土曜日 102
  • 104. そして、 こういうテストコードが できた 103 Developers Summit 2012 2012年9月15日土曜日 103
  • 105. protected static WebDriver driver; @BeforeSuite @Parameters({"browser"}) public static void createDriver( @Optional("firefox") String browser) { if ("firefox".equals(browser)) { driver = new FirefoxDriver(); return; } if ("safari".equals(browser)) { driver = new SafariDriver(); return; } if ("unit".equals(browser)) { driver = new HtmlUnitDriver(); return; } } 104 Developers Summit 2012 2012年9月15日土曜日 104
  • 106. @BeforeMethod public void toLoginPage() { driver.get( "http://localhost:8080/login.html"); } 105 Developers Summit 2012 2012年9月15日土曜日 105
  • 107. @Test public void ログインする() { WebElement userId = driver.findElement(By.name("j_username")); ...(中略)... userId.sendKeys("admin"); password.sendKeys("spring"); loginButton.click(); final int timeoutInSeconds = 3; WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds); wait.until( ExpectedConditions.titleIs("商品一覧画面")); } 106 Developers Summit 2012 2012年9月15日土曜日 106
  • 108. @AfterSuite public static void closeDriver() { driver.quit(); } 107 Developers Summit 2012 2012年9月15日土曜日 107
  • 109. テストコードを 実行してみる 108 Developers Summit 2012 2012年9月15日土曜日 108
  • 110. 109 Developers Summit 2012 2012年9月15日土曜日 109
  • 111. 109 Developers Summit 2012 2012年9月15日土曜日 109
  • 112. まだだ。 まだ終わらんよ! 110 Developers Summit 2012 2012年9月15日土曜日 110
  • 113. クロスブラウザ 111 Developers Summit 2012 2012年9月15日土曜日 111
  • 114. Driverインスタンスを 変えればいい 112 Developers Summit 2012 2012年9月15日土曜日 112
  • 115. マルチプラットフォーム ✕ クロスブラウザ 113 Developers Summit 2012 2012年9月15日土曜日 113
  • 116. WindowsのIEと OS  XのSafariで 動作確認とか… 114 Developers Summit 2012 2012年9月15日土曜日 114
  • 117. こんなこともあろうかと 115 Developers Summit 2012 2012年9月15日土曜日 115
  • 118. 複数ブラウザでの テストを複数マシンで 並列実行する 「Selenium  Grid」 116 Developers Summit 2012 2012年9月15日土曜日 116
  • 119. Test Code Selenium Hub Grid Node Node Node Browser Browser Browser 117 Developers Summit 2012 2012年9月15日土曜日 117
  • 120. 使い方は簡単。 118 Developers Summit 2012 2012年9月15日土曜日 118
  • 121. JARをダウンロードして起動するだけ! // start Hub java -jar selenium-server-standalone-2.25.0.jar -hub // start Node java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://hubserver:4444/grid/register 119 Developers Summit 2012 2012年9月15日土曜日 119
  • 122. テストコードを少し変える // 要求する実行環境。 // ブラウザのバージョンなども指定できる。 DesiredCapabilities capability = DesiredCapabilities.firefox(); // RemoteWebDriverというドライバを使う。 // 要求を満たすブラウザがNodeから選択される。 driver = new RemoteWebDriver( new URL( "http://hubserver:4444/wd/hub"), capability); 120 Developers Summit 2012 2012年9月15日土曜日 120
  • 123. テストコードを少し変える // RemoteWebDriverはTakesScreenshotを実装していない。 // スクリーンショットを撮れるRemoteWebDriverの実装であれば、 // AugmenterがTakesScreenshotインタフェースを追加する。 WebDriver augmentedDriver = new Augmenter().augment(driver); File file = ((TakesScreenshot)augmentedDriver). getScreenshotAs(OutputType.FILE); FileUtils.copyFile(file, new File( "/tmp/" + method.getName() + ".png")); 121 Developers Summit 2012 2012年9月15日土曜日 121
  • 124. そして、 122 Developers Summit 2012 2012年9月15日土曜日 122
  • 125. Selenium  Gridを 使うとき、 123 Developers Summit 2012 2012年9月15日土曜日 123
  • 126. JenkinsとSelenium   Pluginを使うと 便利! 124 Developers Summit 2012 2012年9月15日土曜日 124
  • 127. Jenkinsとは 125 Developers Summit 2012 2012年9月15日土曜日 125
  • 128. CIツール (Continuous  Integration) 126 Developers Summit 2012 2012年9月15日土曜日 126
  • 129. 基本的な使い方としては、 127 Developers Summit 2012 2012年9月15日土曜日 127
  • 130. SCMへのコミットをフックにして 最新のソースコードを取得し、 ビルドやテストを実行する アプリケーション 128 Developers Summit 2012 2012年9月15日土曜日 128
  • 131. 本題と外れるので、 詳細は省略します。 129 Developers Summit 2012 2012年9月15日土曜日 129
  • 132. で、Selenium  Pluginを使って Jenkinsでテストを 実行させる 130 Developers Summit 2012 2012年9月15日土曜日 130
  • 133. Selenium  Pluginが便利! JenkinsサーバがHubになります! Hubを自動起動してくれます! JenkinsのスレーブをNodeとして 自動的にHubに登録してくれます! 131 Developers Summit 2012 2012年9月15日土曜日 131
  • 134. Jenkinsサーバ(マスタ)が GNU/Linuxで あっても 132 Developers Summit 2012 2012年9月15日土曜日 132
  • 135. 余ったWindowsマシンを Jenkinsスレーブにして 133 Developers Summit 2012 2012年9月15日土曜日 133
  • 136. IEでのテストを 実行させよう! 134 Developers Summit 2012 2012年9月15日土曜日 134
  • 137. デモ 135 Developers Summit 2012 2012年9月15日土曜日 135
  • 138. 役割 Jenkinsのマスタサーバ。 OS X Selenium  GridのHub。 Firefoxでのテストを実施する。 Jenkinsのスレーブ。 VirtualBox上 Selenium  GridのNode。 のWindows XP IEでのテストを実施する。 136 Developers Summit 2012 2012年9月15日土曜日 136
  • 139. 137 Developers Summit 2012 2012年9月15日土曜日 137
  • 140. 137 Developers Summit 2012 2012年9月15日土曜日 137
  • 142. まとめ 139 Developers Summit 2012 2012年9月15日土曜日 139
  • 143. Jenkinsサイコー!(違 140 Developers Summit 2012 2012年9月15日土曜日 140
  • 144. ブラウザテストも 自動化できる (部分がある) 141 Developers Summit 2012 2012年9月15日土曜日 141
  • 145. めんどくさいことは できる限りマシンに やらせよう 142 Developers Summit 2012 2012年9月15日土曜日 142
  • 146. 今日のソースコード Github https://github.com/jyukutyo/devsumi-­kansai2012 https://github.com/jyukutyo/devsumi-­kansai2012-­Grid 143 Developers Summit 2012 2012年9月15日土曜日 143
  • 147. ご清聴 ありがとうございました! 144 Developers Summit 2012 2012年9月15日土曜日 144