{"id":28927,"date":"2015-10-26T11:46:49","date_gmt":"2015-10-26T06:16:49","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=28927"},"modified":"2016-09-14T19:00:17","modified_gmt":"2016-09-14T13:30:17","slug":"mobile-web-automation-with-appium-2","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mobile-web-automation-with-appium-2\/","title":{"rendered":"Mobile Web Automation with Appium"},"content":{"rendered":"<p>Appium is an open source tool for mobile application. It is a bridge or we can say in simple terms it is a mediator between PC and mobile.<\/p>\n<p>It supports three types of mobile application i.e. native, web application and hybrid.<\/p>\n<p>Native Applications\u00a0are developed for use on a particular device or platform. It is installed directly on a mobile device and developers create a separate app version for each mobile device.<\/p>\n<p>Mobile web application are called mobile website and can be accessed through browser by hitting the URL.<\/p>\n<p>Hybrid application combines elements of both native and web applications. Like mobile native apps, you can find and download mobile hybrid apps using the Google Play Store or the Apple\u2019s App Store.\u00a0Similar to mobile web app, a mobile hybrid app would look alike to a mobile website that can be accessed by hitting an URL in the web browser.<\/p>\n<p>For example Web apps, such as online banking services or locally stored native apps, such as Microsoft Excel.<\/p>\n<p>To install an Appium we need .net framework<\/p>\n<p>What are the desired capabilities?<\/p>\n<p>Desired Capabilities are a set of keys and values sent to the Appium server to tell the server what kind of automation session we are interested in starting up.<\/p>\n<p><span style=\"color: #333333\"><strong><strong>\u00a0<\/strong><\/strong><\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"color: #333333\"><b>KEYS<\/b><\/span><\/td>\n<td><span style=\"color: #333333\"><b>DESCRIPTION<\/b><\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #333333\">browserName<\/span><\/td>\n<td><span style=\"font-weight: 400;color: #333333\">Name of mobile web browser<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #333333\">appium-version<\/span><\/td>\n<td><span style=\"font-weight: 400;color: #333333\">Version of Appium<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #333333\">platform Version<\/span><\/td>\n<td><span style=\"font-weight: 400;color: #333333\">Mobile OS version<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #333333\">deviceName<\/span><\/td>\n<td><span style=\"font-weight: 400;color: #333333\">Kind of mobile devices to use<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;color: #333333\">platformName<\/span><\/td>\n<td><span style=\"font-weight: 400;color: #333333\">Kind of mobile OS platform to use<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #333333\"><b>Automation Test<\/b><\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"color: #333333\"><span style=\"font-weight: 400\">Attach Android device with your system and type <\/span><b>adb device<\/b><span style=\"font-weight: 400\"> command on cmd prompt to verify that the device is attached or not<\/span><\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"color: #333333\"><span style=\"font-weight: 400\">Launch Appium tool on your machine<\/span><\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400;color: #333333\">Once the Appium is launched run the script written on the Eclipse<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">Use case we are going to automate<\/span><span style=\"font-weight: 400\">:<\/span><\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;color: #333333\"> To check the title of the web page<\/span><\/li>\n<li><span style=\"font-weight: 400;color: #333333\"> Enter all the details in the Contact Us form except message detail<\/span><\/li>\n<li><span style=\"font-weight: 400;color: #333333\"> Click on the Submit button<\/span><\/li>\n<li><span style=\"font-weight: 400;color: #333333\"> To verify the error message. <\/span><\/li>\n<\/ol>\n<p><span style=\"color: #333333\"><strong><strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-28928\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/10\/appium_image.png\" alt=\"appium_image\" width=\"414\" height=\"659\" \/><\/strong><\/strong><\/span><\/p>\n<p><span style=\"color: #333333\">\/\/setup the desired capability and pass the android activity<strong><strong><br \/>\n<\/strong><\/strong><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">DesiredCapabilities <\/span><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\"> = <\/span><b>new<\/b><span style=\"font-weight: 400\"> DesiredCapabilities();<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">.setCapability(<\/span><span style=\"font-weight: 400\">&#8220;browserName&#8221;<\/span><span style=\"font-weight: 400\">, <\/span><span style=\"font-weight: 400\">&#8220;chrome&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">.setCapability(<\/span><span style=\"font-weight: 400\">&#8220;appium-version&#8221;<\/span><span style=\"font-weight: 400\">, <\/span><span style=\"font-weight: 400\">&#8220;1.4.0&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">.setCapability(<\/span><span style=\"font-weight: 400\">&#8220;VERSION&#8221;<\/span><span style=\"font-weight: 400\">,<\/span><span style=\"font-weight: 400\">&#8220;5.1.1&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">.setCapability(<\/span><span style=\"font-weight: 400\">&#8220;deviceName&#8221;<\/span><span style=\"font-weight: 400\">,<\/span><span style=\"font-weight: 400\">&#8220;ANDROID&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">.setCapability(<\/span><span style=\"font-weight: 400\">&#8220;platformName&#8221;<\/span><span style=\"font-weight: 400\">,<\/span><span style=\"font-weight: 400\">&#8220;ANDROID&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">RemoteWebDriver <\/span><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\"> = <\/span><b>new<\/b><span style=\"font-weight: 400\"> RemoteWebDriver(<\/span><b>new<\/b><span style=\"font-weight: 400\"> URL(<\/span><span style=\"font-weight: 400\">&#8220;http:\/\/127.0.0.1:4723\/wd\/hub&#8221;<\/span><span style=\"font-weight: 400\">), <\/span><span style=\"font-weight: 400\">cap<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"font-weight: 400;color: #333333\">\/\/ Navigate to the page and interact with the elements<\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.get(<\/span><span style=\"font-weight: 400\">&#8220;http:\/\/www.tothenew.com\/contact-us&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">System.<\/span><b><i>out<\/i><\/b><span style=\"font-weight: 400\">.println(<\/span><span style=\"font-weight: 400\">&#8220;Android Title is: &#8220;<\/span><span style=\"font-weight: 400\"> + <\/span><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.getTitle());<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;firstname&#8221;<\/span><span style=\"font-weight: 400\">)).sendKeys(<\/span><span style=\"font-weight: 400\">&#8220;kimi&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;lastname&#8221;<\/span><span style=\"font-weight: 400\">)).sendKeys(<\/span><span style=\"font-weight: 400\">&#8220;agarwal&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;email&#8221;<\/span><span style=\"font-weight: 400\">)).sendKeys(<\/span><span style=\"font-weight: 400\">&#8220;kimiagarwal@yahoo.com&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;phone&#8221;<\/span><span style=\"font-weight: 400\">)).sendKeys(<\/span><span style=\"font-weight: 400\">&#8220;9999123456&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;company&#8221;<\/span><span style=\"font-weight: 400\">)).sendKeys(<\/span><span style=\"font-weight: 400\">&#8220;ABC Company&#8221;<\/span><span style=\"font-weight: 400\">);<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">xpath<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;.\/\/*[@type=&#8217;checkbox&#8217;][@value=&#8217;Job&#8217;]&#8221;<\/span><span style=\"font-weight: 400\">)).click();<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">xpath<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;.\/\/*[@type=&#8217;submit&#8217;]&#8221;<\/span><span style=\"font-weight: 400\">)).click(); <\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">WebElement <\/span><span style=\"font-weight: 400\">msg<\/span><span style=\"font-weight: 400\"> = <\/span><span style=\"font-weight: 400\">driver<\/span><span style=\"font-weight: 400\">.findElement(By.<\/span><i><span style=\"font-weight: 400\">id<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;message-error&#8221;<\/span><span style=\"font-weight: 400\">));<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">System.<\/span><b><i>out<\/i><\/b><span style=\"font-weight: 400\">.println(<\/span><span style=\"font-weight: 400\">msg<\/span><span style=\"font-weight: 400\">.getText());<\/span><\/span><\/p>\n<p><span style=\"color: #333333\"><span style=\"font-weight: 400\">Assert.<\/span><i><span style=\"font-weight: 400\">assertEquals<\/span><\/i><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">&#8220;Please enter the message&#8221;<\/span><span style=\"font-weight: 400\">, <\/span><span style=\"font-weight: 400\">msg<\/span><span style=\"font-weight: 400\">.getText());<\/span><\/span><\/p>\n<p>Tell me what you think of this in the comments section. Happy testing \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Appium is an open source tool for mobile application. It is a bridge or we can say in simple terms it is a mediator between PC and mobile. It supports three types of mobile application i.e. native, web application and hybrid. Native Applications\u00a0are developed for use on a particular device or platform. It is installed [&hellip;]<\/p>\n","protected":false},"author":107,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":10},"categories":[1818,1816],"tags":[1561,14,2654,4851],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28927"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/107"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=28927"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28927\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=28927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=28927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=28927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}