{"id":963,"date":"2019-01-08T18:22:42","date_gmt":"2019-01-08T17:22:42","guid":{"rendered":"http:\/\/blogs.igalia.com\/carlosgc\/?p=963"},"modified":"2019-01-08T18:22:42","modified_gmt":"2019-01-08T17:22:42","slug":"epiphany-automation-mode","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/carlosgc\/2019\/01\/08\/epiphany-automation-mode\/","title":{"rendered":"Epiphany automation mode"},"content":{"rendered":"<p>Last week I finally found some time to <a href=\"https:\/\/gitlab.gnome.org\/GNOME\/epiphany\/commit\/28a84367b866dd277d7f3a0f063d20ccef240a4e\">add the automation mode to Epiphany<\/a>, that allows to run automated tests using <a href=\"https:\/\/w3c.github.io\/webdriver\/\">WebDriver<\/a>. It&#8217;s important to note that the automation mode is not expected to be used by users or applications to control the browser remotely, but only by WebDriver automated tests. For that reason, the automation mode is incompatible with a primary user profile. There are a few other things affected by the auotmation mode:<\/p>\n<ul>\n<li>There&#8217;s no persistency. A private profile is created in tmp and only ephemeral web contexts are used.<\/li>\n<li>URL entry is not editable, since users are not expected to interact with the browser.<\/li>\n<li>An info bar is shown  to notify the user that the browser is being controlled by automation.<\/li>\n<li>The window decoration is orange to make it even clearer that the browser is running in automation mode.<\/li>\n<\/ul>\n<p>So, how can I write tests to be run in Epiphany? First, you need to install a recently enough <a href=\"https:\/\/www.seleniumhq.org\/\">selenium<\/a>. For now, only the <a href=\"https:\/\/pypi.org\/project\/selenium\/\">python API<\/a> is supported. Selenium doesn&#8217;t have an Epiphany driver, but the <a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\/tree\/master\/py\/selenium\/webdriver\/webkitgtk\">WebKitGTK driver<\/a> can be used with any WebKitGTK+ based browser, by providing the browser information as part of session capabilities.<\/p>\n<pre>\nfrom selenium import webdriver\n\noptions = webdriver.WebKitGTKOptions()\noptions.binary_location = 'epiphany'\noptions.add_argument('--automation-mode')\noptions.set_capability('browserName', 'Epiphany')\noptions.set_capability('version', '3.31.4')\n\nephy = webdriver.WebKitGTK(options=options, desired_capabilities={})\nephy.get('http:\/\/www.webkitgtk.org')\nephy.quit()\n<\/pre>\n<p>This is a very simple example that just opens Epiphany in automation mode, loads http:\/\/www.webkitgtk.org and closes Epiphany. A few comments about the example:<\/p>\n<ul>\n<li>Version 3.31.4 will be the first one including the automation mode. <\/li>\n<li>The parameter desired_capabilities shouldn&#8217;t be needed, but there&#8217;s a <a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\/pull\/6814\">bug in selenium that has been fixed very recently<\/a>. <\/li>\n<li>WebKitGTKOptions.set_capability was added in selenium 3.14, if you have an older version you can use the following snippet instead<\/li>\n<\/ul>\n<pre>\nfrom selenium import webdriver\n\noptions = webdriver.WebKitGTKOptions()\noptions.binary_location = 'epiphany'\noptions.add_argument('--automation-mode')\ncapabilities = options.to_capabilities()\ncapabilities['browserName'] = 'Epiphany'\ncapabilities['version'] = '3.31.4'\n\nephy = webdriver.WebKitGTK(desired_capabilities=capabilities)\nephy.get('http:\/\/www.webkitgtk.org')\nephy.quit()\n<\/pre>\n<p>To simplify the driver instantation you can create your own Epiphany driver derived from the WebKitGTK one:<\/p>\n<pre>\nfrom selenium import webdriver\n\nclass Epiphany(webdriver.WebKitGTK):\n    def __init__(self):\n        options = webdriver.WebKitGTKOptions()\n        options.binary_location = 'epiphany'\n        options.add_argument('--automation-mode')\n        options.set_capability('browserName', 'Epiphany')\n        options.set_capability('version', '3.31.4')\n\n        webdriver.WebKitGTK.__init__(self, options=options, desired_capabilities={})\n\nephy = Epiphany()\nephy.get('http:\/\/www.webkitgtk.org')\nephy.quit()\n<\/pre>\n<p>The same for selenium &lt; 3.14<\/p>\n<pre>\nfrom selenium import webdriver\n\nclass Epiphany(webdriver.WebKitGTK):\n    def __init__(self):\n        options = webdriver.WebKitGTKOptions()\n        options.binary_location = 'epiphany'\n        options.add_argument('--automation-mode')\n        capabilities = options.to_capabilities()\n        capabilities['browserName'] = 'Epiphany'\n        capabilities['version'] = '3.31.4'\n\n        webdriver.WebKitGTK.__init__(self, desired_capabilities=capabilities)\n\nephy = Epiphany()\nephy.get('http:\/\/www.webkitgtk.org')\nephy.quit()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Last week I finally found some time to add the automation mode to Epiphany, that allows to run automated tests using WebDriver. It&#8217;s important to note that the automation mode is not expected to be used by users or applications &hellip; <a href=\"https:\/\/blogs.igalia.com\/carlosgc\/2019\/01\/08\/epiphany-automation-mode\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6,7,8],"tags":[21,23,22],"class_list":["post-963","post","type-post","status-publish","format-standard","hentry","category-free-software","category-gnome","category-igalia","category-webkit","tag-epiphany","tag-webdriver","tag-webkit"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/posts\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":5,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/posts\/963\/revisions"}],"predecessor-version":[{"id":968,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/posts\/963\/revisions\/968"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/media?parent=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/carlosgc\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}