{"id":169,"date":"2013-05-03T15:56:45","date_gmt":"2013-05-03T15:56:45","guid":{"rendered":"http:\/\/blog.mozilla.org\/webqa\/?p=169"},"modified":"2013-05-03T15:56:45","modified_gmt":"2013-05-03T15:56:45","slug":"part-4-ui-testing-system-dialogs-are-html","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/fxtesteng\/2013\/05\/03\/part-4-ui-testing-system-dialogs-are-html\/","title":{"rendered":"Part 4: UI Testing on Firefox OS. System dialogs are HTML, too!"},"content":{"rendered":"<p>By Zac Campbell<\/p>\n<p>Greetings Gaia UI testing blog readers. If you\u2019ve come this far then you\u2019re well aware that Firefox OS\u2019s front end is an HTML operating system. This means that system prompts and dialogs like javascript.alert are written in HTML too.<\/p>\n<p>If you\u2019ve used Selenium you may have found that it\u2019s difficult to interact with elements that are in the browser itself, like download prompts and so forth. With Firefox OS things are different. Marionette, our test harness, lets us traverse up and down between the system and webapp. If you\u2019re familiar with the architecture of Firefox you\u2019ll know this as the browser chrome and content respectively.<\/p>\n<p>Fortunate, too, because in Firefox OS there are some additional system prompts like &lt;select&gt; boxes that are shown at the system level. The reason this is done is to present to the user a usable list of options on the small screen mobile device. You might have seen this behaviour already on iOS and Android devices if you own one.<\/p>\n<p><a href=\"http:\/\/blog.mozilla.org\/fxtesteng\/files\/2013\/05\/select_wrapper.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blog.mozilla.org\/fxtesteng\/files\/2013\/05\/select_wrapper.jpg\" alt=\"select_wrapper\" width=\"760\" height=\"480\" class=\"alignnone size-full wp-image-170\" srcset=\"https:\/\/blog.mozilla.org\/fxtesteng\/files\/2013\/05\/select_wrapper.jpg 760w, https:\/\/blog.mozilla.org\/fxtesteng\/files\/2013\/05\/select_wrapper-300x189.jpg 300w, https:\/\/blog.mozilla.org\/fxtesteng\/files\/2013\/05\/select_wrapper-600x379.jpg 600w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/a><\/p>\n<p>What\u2019s happening in this example is this;<br \/>\n1. Firefox OS\u2019s System is detecting that the user has tapped on the &lt;select&gt; box inside the Settings web app.<br \/>\n2. The system copies all of the options in the box and inserts them into a &lt;ol&gt; element at the system level.<br \/>\n3. The &lt;ol&gt; element is then shown to the user with the \u2018OK\u2019 box button<br \/>\n4. After the user has selected their option, Firefox OS feeds the user\u2019s selection back to the web app.<\/p>\n<p>To interact with this system box using Marionette we need to do some frame switching from the Settings app into the System app! I covered this in detail in <a href=\"http:\/\/blog.mozilla.org\/webqa\/2013\/02\/13\/part-2-ui-testing-on-firefox-os-working-with-iframes\/\" title=\"Part 2: UI Testing on Firefox OS. Working with iframes\">part 2<\/a> of the blog series.<\/p>\n<p>An important point to note is that the locator for the &lt;select&gt; box in the web app will be different in the System app because the System app compiles its own HTML. The common links between them are the number of options and the text value of the option. Thus in our code we will locate the option using the element&#8217;s text value.<\/p>\n<p>The workflow for achieving this in our test is:<br \/>\n1. Switch back to the System app<br \/>\n2. Find the HTML locator for the list item<br \/>\n3. Click the list item to choose it<br \/>\n4. Find the HTML locator for the OK button<br \/>\n5. Click OK<br \/>\n6. Switch frame into the web app then resume the test steps.<\/p>\n<p>Here is the HTML in the system app for the example:<\/p>\n<pre>\n<section id=\"value-selector-container\">\n <h1>\n   Select\n <\/h1>\n\n <ol role=\"listbox\">\n  <!-- snip -->\n     <li>\n           <label for=\"gaia-option-23\"><span>London<\/span><\/label>\n     <\/li>\n     <li>\n           <label for=\"gaia-option-24\"><span>Luxembourg<\/span><\/label>\n     <\/li>\n     <li>\n           <label for=\"gaia-option-25\"><span>Madrid<\/span><\/label>\n     <\/li>\n  <!-- snip -->\n <\/ol>\n<\/section>\n<\/pre>\n<p>Now here\u2019s how we\u2019ll write the test to select the option box:<\/p>\n<pre>\n# Switch back to System frame\nself.marionette.switch_to_frame()\n\n# Find the \u2018Madrid\u2019 <li> using an Xpath locator\n# Marionette\u2019s implicit wait will wait for Gaia to create it\nlist_item = self.marionette.find_element(\"xpath\", \n    \"\/\/section[@id='value-selector-container']\/\/li[label[span[text()='%s']]]\" % 'Madrid')\n\n# Click the list item\nlist_item.click()\n\n# Now find and click \u2018OK\u2019\nclose_button = self.marionette.find_element('css selector', 'button.value-option-confirm')\nclose_button.click()\n\n# Find and switch back to the Settings app frame\nsettings_frame = self.marionette.find_element(*settings_frame_locator)\nself.marionette.switch_to_frame(settings_frame)\n\n# OK now we\u2019re back in the Settings app the test can continue\n<\/pre>\n<p>You may like to create a wrapper method for this to save yourself some duplication.<\/p>\n<p>We can access all sorts of system dialogs in Firefox OS like notifications (that slide out from the status bar), app install notifications, alert boxes, lockscreens and so forth.<\/p>\n<p>With Firefox OS and Marionette we have great powers to automate end-to-end testing and integration between the operating system and webapp content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Zac Campbell Greetings Gaia UI testing blog readers. If you\u2019ve come this far then you\u2019re well aware that Firefox OS\u2019s front end is an HTML operating system. This means &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/fxtesteng\/2013\/05\/03\/part-4-ui-testing-system-dialogs-are-html\/\">Read more<\/a><\/p>\n","protected":false},"author":1359,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24660],"tags":[8630,228,4261,24660,27793],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/169"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/users\/1359"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}