-自動テストについてまとめたページ

*プロダクト [#r5b127ee]

**JSoup [#raac5768]


|クラスで複数取得|Elements masthead = doc.select("div.masthead");|
|クラスで単数取得|Element masthead = doc.select("div.masthead").first();|
|階層構造で複数取得|Elements resultLinks = doc.select("h3.r > a"); // direct a after h3|
|ファイルから読み込み|Document doc = Jsoup.parse(new File("/tmp/input.html"), "UTF-8", "http://example.com/");|

**HTMLUnit [#ea6e5f7a]

-value属性をセット。value以外にもセットできる。

 HtmlElement input = page.getHtmlElementById(id);
 input.setAttribute("value", value);

-webclient.getPageの引数にfile://を指定するとローカルのファイルも指定可能だが、相対パスのファイルを全部用意しないといけないので面倒。

 webClient.getPage("file:///Users/

**XPath [#xc1e5e21]

-getFirstByXpathを使うと一個だけ取得できる

|//a[@id='idname']|AタグのIDで抽出|
|//a[@href='/login.html']|Aタグのリンク先で抽出|
|//input[@type='submit']|type=submitのタグを取得|
|//input[@value='検索']|検索のinputタグを取得|
|//td[contains(.,'検索したい文字列')]|検索したい文字列が含まれているものを取得|
|img[alt='ログアウト']|altで検索|
|//a[text()='ログアウト']"|Aのテキストで検索|

-複数取得する場合はLIST

|final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@name='John']").get(0);|無理やりキャスト|

**xpathの検証 [#fe0b93a0]

chromeのコンソールで$x('xpath')でOK!

**htmlunit [#x50af09f]

主にPHPバッチで利用

|クラスやID指定|div[class=tbl-pc]|
|親子関係|table tbody tr td|


*Selenium(java ラッパーで Selenide がある) [#k23e2daf]

** [#m92a49fb]

**Macでwebdriver [#gd9dbecb]

***成功バージョン [#kd34fd8d]

-chromedriverを入れる

 brew update
 brew install chromedriver

-ドライバーの位置を指定する



***失敗バージョン [#p20f8e2a]

 brew update
 brew install selenium-server-standalone
 brew install chromedriver

だとだめ!jarを直接実行する。

 java -Dwebdriver.chrome.bin="/Applications/Google Chrome.app" -Dwebdriver.chrome.drir=/usr/local/bin/chromedriver -jar selenium-server-standalone-3.4.0.jar

しかし上記のchromedriverさえインストールできればあとはサーバー不要なのであった!


**JMeter [#hfe22ad2]

**Geb(groovy) [#ac422465]


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS