WebDriver

WebDriver

[135] WebDriver は、 Webブラウザーを操作する Web API です。 利用者にかわって利用者インターフェイスを操作したり、 閲覧文脈に表示中の WebページDOM にアクセスしたりできます。

仕様書

プロトコル

[145] WebDriver エンドポイント

WebDriver の実装

[35] サーバー側:

[36] クライアントは、世間では Selenium言語依存の専用のクライアントライブラリーを使うことが多いですが、 WebDriver は単なる Web API なので、普通の HTTPライブラリーがあれば利用できます。

[37] しかし定型処理がわずらわしくなりますから、素の HTTP のまま操作するよりは、 ある程度抽象化されたクライアントライブラリーは欲しいですね。

非互換性

[38] 色々な WebDriver の実装は、似て非なるプロトコルを使っています。

[39] Selenium のサーバーではパスの先頭に /wd/hub が付きます。 ChromeDriverGeckoDriver ではパス全体が WebDriver 仕様のものと解釈されます。

[40] WebDriver 仕様上は HTTP状態符号で正常かエラーかを表しますが、 ChromeDriver は基本的に 200 を使います。 応答本体JSONstatus0 なら成功、 それ以外なら何らかのエラーです。 valueJSONオブジェクトとなり、その message人間向けのエラーメッセージが入ります。

[43] WebDriver 仕様ではスクリプトの実行は /session/{session_id}/execute/sync となっていますが、 ChromeDriver では /session/{session_id}/execute です。

[42] ChromeDriver では /statusGET するとビルド環境の情報が得られます。

[103]エンドポイントの項も参照。

用途

[70] WebDriver を使った Webブラウザー操作の利用例

実装

[143] Chrome は、WebDriver による操作中、 アドレスバー下の情報バーに 「Chrome is being controlled by automated software.」とその旨を表示します。 セッション作成時に chromeOptions"excludeSwitches": ["enable-automation"] と指定して抑制できますが、 今度は 「Disable developer mode extensions」 というメッセージがオーバーレイ表示されるようになりますw

[146] 要求本体にはJSONを指定しますが、 ChromeDriverGeckoDriverContent-Type なしでも受け付けてくれるようにみえます。

[147] GeckoDriver は存在しないコマンドを送信されたエラーを返した後、 不完全な形でHTTP接続を閉じることがよくある(が必ずではない)ようです。 クライアント側にTCPが閉じられたことが伝わらず、 クライアントがまだ接続が生きていると思って次のHTTP要求を送信すると、 (おそらく RST が送られて) broken pipe (EPIPE) エラーになるという感じです。

[148] >>147 パケットキャプチャーして調べたわけではないので GeckoDriver 側の RST ではなくクライアントの OS からアプリケーションに接続が閉じられたのが伝わっていないのに write してエラーになってるのかもしれないけど。 どっちにしても接続が異常に閉じられてはいるようだし、 ChromeDriver や一般のサーバーではこんなことにはならないので。。。

navigator.webdriver

[150] Chrome--headless 付きで起動すると navigator.webdriverにします。

歴史

[149] 最速インターフェース研究会 :: Firefoxの拡張MozLabの中に含まれるMozReplがヤバすぎる件について, 2006-09-28 00:48, http://la.ma.la/blog/diary_200609280045.htm

[1] JsonWireProtocol - selenium - A description of the protocol used by WebDriver to communicate with remote instances - Browser automation framework - Google Project Hosting ( ( 版)) http://code.google.com/p/selenium/wiki/JsonWireProtocol

[33] JsonWireProtocol - selenium - A description of the protocol used by WebDriver to communicate with remote instances - Browser automation framework - Google Project Hosting () https://web.archive.org/web/20160205035909/https://code.google.com/p/selenium/wiki/JsonWireProtocol

[2] WebDriver ( ( 版)) http://www.w3.org/TR/2012/WD-webdriver-20120710/

[3] WebDriver ( ( 版)) http://www.w3.org/TR/2013/WD-webdriver-20130117/

[4] WebDriver ( ( 版)) http://www.w3.org/TR/2013/WD-webdriver-20130312/

[5] JsonWireProtocol - selenium - A description of the protocol used by WebDriver to communicate with remote instances - Browser automation framework - Google Project Hosting ( ( 版)) https://code.google.com/p/selenium/wiki/JsonWireProtocol

[6] JsonWireProtocol - selenium - A description of the protocol used by WebDriver to communicate with remote instances - Browser automation framework - Google Project Hosting ( ( 版)) https://code.google.com/p/selenium/wiki/JsonWireProtocol#Capabilities_JSON_Object

[7] WebDriver ( ( 版)) https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html

[8] Selenium WebDriver — Selenium Documentation ( ( 版)) http://docs.seleniumhq.org/docs/03_webdriver.jsp

[9] The Architecture of Open Source Applications: Selenium WebDriver ( ( 版)) http://www.aosabook.org/en/selenium.html

[10] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150803/

[11] WebDriver ( 版) https://w3c.github.io/webdriver/webdriver-spec.html

[12] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150804/

[13] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150805/

[14] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150808/

[15] WebDriver now a living standard ( 版) https://sny.no/2015/08/living

[16] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150827/

[17] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150902/

[18] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150909/

[19] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150915/

[20] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150918/

[21] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20150921/

[22] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20151025/

[23] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20151028/

[24] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20151029/

[25] Microsoft Edge 用 WebDriver (Windows) ( 版) https://msdn.microsoft.com/ja-jp/library/mt188085(v=vs.85).aspx

Microsoft Edge の WebDriver 実装では既存のテストとの下位互換のために、W3C WebDriver 実装と JSON Wire Protocol の両方をサポートします。

[26] Bringing automated testing to Microsoft Edge through WebDriver | Microsoft Edge Dev Blog ( 版) https://blogs.windows.com/msedgedev/2015/07/23/bringing-automated-testing-to-microsoft-edge-through-webdriver/

[27] Developer Resources : Microsoft Edge Dev ( 版) https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/

[28] WebDriver ( 版) http://www.w3.org/TR/2015/WD-webdriver-20151109/

[29] WebDriver ( 版) https://www.w3.org/TR/2016/WD-webdriver-20160120/

[31] WebDriver ( 版) https://www.w3.org/TR/2016/WD-webdriver-20160426/

[32] WebDriver ( ()) https://www.w3.org/TR/2016/WD-webdriver-20160523/

[34] WebDriver Status - Mozilla | MDN ( ()) https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status

[44] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20160830/

[45] WebDriver Support in Safari 10 | WebKit () https://webkit.org/blog/6900/webdriver-support-in-safari-10/

[46] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161013/

[47] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161019/

[48] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161021/

[49] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161025/

[50] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161031/

[51] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161115/

[52] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161116/

[53] WebDriver () https://www.w3.org/TR/2016/WD-webdriver-20161129/

[54] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170105/

[55] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170110/

[56] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170111/

[57] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170112/

[58] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170113/

[59] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170116/

[60] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170117/

[61] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170118/

[62] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170119/

[63] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170120/

[64] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170121/

[65] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170123/

[66] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170124/

[67] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170125/

[68] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170126/

[69] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170127/

[77] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170131/

[78] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170201/

[79] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170202/

[80] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170203/

[81] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170206/

[82] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170207/

[83] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170209/

[84] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170210/

[85] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170213/

[86] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170214/

[87] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170215/

[88] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170217/

[89] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170218/

[90] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170219/

[91] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170220/

[92] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170221/

[93] Toggle spec to CR status (sideshowbarker著, ) https://github.com/w3c/webdriver/commit/6273b09685132df5715ba707d2d57e53bf508ac6

[94] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170222/

[95] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170223/

[96] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170224/

[97] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170228/

[98] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170301/

[99] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170302/

[100] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170306/

[101] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170307/

[102] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170308/

[41] Transition Request: WebDriver to Candidate Recommendation (Michael[tm] Smith著, ) https://lists.w3.org/Archives/Public/www-archive/2017Mar/0000.html

[104] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170312/

[105] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170316/

[106] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170320/

[107] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170322/

[108] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170324/

[109] WebDriver () https://www.w3.org/TR/2017/WD-webdriver-20170329/

[110] WebDriver () https://www.w3.org/TR/2017/CR-webdriver-20170330/

[111] WebDriver について私が知っていること (2017 年版) - ひだまりソケットは壊れない () http://vividcode.hatenablog.com/entry/web-driver-introduction-2017

[112] webdriverio/webdriverio: A Node.js bindings implementation for the W3C WebDriver protocol () https://github.com/webdriverio/webdriverio

[113] WebDriver によるスクリプト実行の現状 (geckodriver と ChromeDriver) - ひだまりソケットは壊れない () http://vividcode.hatenablog.com/entry/web-driver/how-to-execute-script

[114] interface: mark navigator.webdriver as unforgeable (andreastt著, ) https://github.com/w3c/webdriver/commit/b50038af851ca2d11edfe0a70f568332f50d0ac4

[115] Rephrase description of navigator.webdriver (shekyan著, ) https://github.com/w3c/webdriver/commit/48e8c855facbcbc8682d734c0922ce69d71ce248

[116] disable auto publish since the spec is now CR (deniak著, ) https://github.com/w3c/webdriver/commit/0d62ec62c2c18502cd7ebd20452a0d0a7fc90508

[117] Changes around navigator.webdriver (shekyan著, ) https://github.com/w3c/webdriver/commit/96a38f2415aa59bbe370aaafb451b01b0dccfe39

[118] Changes around navigator.webdriver by shekyan · Pull Request #948 · w3c/webdriver () https://github.com/w3c/webdriver/pull/948

[119] Remove obsolete W3C bug tracker link. (joshbruning著, ) https://github.com/w3c/webdriver/commit/95929cd3e87eb25c5ff53bb7aea4a840d30df4f2

[120] Remove obsolete W3C bug tracker link. by joshbruning · Pull Request #978 · w3c/webdriver () https://github.com/w3c/webdriver/pull/978

[121] Structuring WebDriver callback code (Geoffrey Sneddon著, ) https://lists.w3.org/Archives/Public/www-archive/2017Jul/0001.html

[122] Transition Request: WebDriver to Proposed Recommendation (Michael[tm] Smith著, ) https://lists.w3.org/Archives/Public/www-archive/2017Sep/0000.html

[123] ページ遷移が終わって読み込みが終わったら~~~みたいな条件でテストを書くのが難しい。ただでさえ面倒くさいのに、ブラウザーごとに微妙に WebDriver の動作が違ったり、(たぶん)たまたまのタイミングの問題でうまくいったりいかなかったりするのでますます難しい。普通に思った通りに書いても基本的に動かない。。。

そして本当に書きたいことを書くのがまた難しい。ここをクリックしたあとに画面にこの要素がいい感じに見えていたらOK、みたいなのはたぶん書こうと思えば書けるんだけど簡単には書けない。そういうテストを書いてこそ意味がある気がするが難しい。

WebDriver API の上に便利APIをいっぱい作らないとつらそうだ・・・。

[124] しかもそういうのって開発の途中やリニューアル的なタイミングで要素の構造や表示位置が変わったりするので、 それを想定して壊れなそうに書く必要があって、それがまたむずいのよね。

[125] ios-driver documentation (François Reynaud著, ) https://ios-driver.github.io/ios-driver/?page=home

[126] WebDriver Support in Safari 10 | WebKit () https://webkit.org/blog/6900/webdriver-support-in-safari-10/

[127] Appium: モバイルアプリのテスト自動化はすごいことになった () http://appium.io/

[128] Generalize protocol extension mechanism (#1177) (jugglinmike著, ) https://github.com/w3c/webdriver/commit/971ab897921b3a84ce5c426fefca5c9b3d2ebff2

[129] Improve wording around extension commands · Issue #1142 · w3c/webdriver () https://github.com/w3c/webdriver/issues/1142

[130] Generalize protocol extension mechanism by jugglinmike · Pull Request #1177 · w3c/webdriver () https://github.com/w3c/webdriver/pull/1177

[131] interface: expose navigator.webdriver unconditionally (andreastt著, ) https://github.com/w3c/webdriver/commit/a224627dcea6448367523bf0420de3d547946300

[132] Expose navigator.webdriver regardless of whether we're running under automation or not · Issue #1214 · w3c/webdriver () https://github.com/w3c/webdriver/issues/1214

[133] interface: expose navigator.webdriver unconditionally by andreastt · Pull Request #1219 · w3c/webdriver () https://github.com/w3c/webdriver/pull/1219

[134] Transition Request: WebDriver to Proposed Recommendation (Michael[tm] Smith著, ) https://lists.w3.org/Archives/Public/www-archive/2018Mar/0003.html

[136] Re: Transition Request: WebDriver to Proposed Recommendation (Michael[tm] Smith著, ) https://lists.w3.org/Archives/Public/www-archive/2018Apr/0000.html

[137] New WebKit Features in Safari 11.1 | WebKit () https://webkit.org/blog/8216/new-webkit-features-in-safari-11-1/

[138] Transition Request: WebDriver to Recommendation (Michael[tm] Smith著, ) https://lists.w3.org/Archives/Public/www-archive/2018May/0004.html

[139] Web Driver re-charter · Issue #126 · w3c/strategy () https://github.com/w3c/strategy/issues/126

[140] WebDriver () https://w3c.github.io/webdriver/

[141] mobile-spec/spec-draft.md at master · SeleniumHQ/mobile-spec () https://github.com/SeleniumHQ/mobile-spec/blob/master/spec-draft.md

[142] Capabilities & ChromeOptions - ChromeDriver - WebDriver for Chrome () https://chromedriver.chromium.org/capabilities

[144] Navigator.webdriver - Web APIs | MDN () https://developer.mozilla.org/en-US/docs/Web/API/Navigator/webdriver