Friday, 29 May 2015

Appium C# - Executing 'Appium-Webdriver' automation script on mobile device

This session demonstrates automating the script for 'EriBank' app and executing the automation script in mobile device using Visual Studio with C#.

Prerequisites:
- Java is installed
- Set path for Java
- Android SDK is installed
- Set path for Android SDK
- Appium Server is installed

  Refer below url's for installation/configuration.
  http://automation-home.blogspot.in/2015/05/appium-installation.html 
  http://automation-home.blogspot.com/2015/05/appium-uiautomatorviewer.html

- Developer Options are enabled in mobile device
- USB Debugging is enabled in mobile device

Note: 
  'Eribank.apk' can be downloaded from 'http://code.google.com/p/eribank/downloads/list'

Video Session covers below topics:
- Visual Studio

Adding Webdriver, JSON.net and Appium to the references.
- Webdriver 
- JSON.net
- Appium

- Inspecting the locators/elements in the mobile device app(.apk)

Watch Demo

Sample Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System.Threading;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;

namespace ERiBankTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AppiumDriver driver;
            Console.WriteLine("Executing Appium Script");

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("deviceName", "Test");
            capabilities.SetCapability("platformVersion", "4.4.4");
            capabilities.SetCapability("platformName", "Android");

            capabilities.SetCapability("appPackage", "com.experitest.ExperiBank");
            capabilities.SetCapability("appActivity", ".LoginActivity");

            driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);

            //userName - com.experitest.ExperiBank:id/usernameTextField            driver.FindElement(By.Id("com.experitest.ExperiBank:id/usernameTextField")).SendKeys("company");

            //pwd- com.experitest.ExperiBank:id/passwordTextField      driver.FindElement(By.Id("com.experitest.ExperiBank:id/passwordTextField")).SendKeys("company");

            //login- com.experitest.ExperiBank:id/loginButton
            driver.FindElement(By.Id("com.experitest.ExperiBank:id/loginButton")).Click();

            //logout - com.experitest.ExperiBank:id/logoutButton
            driver.FindElement(By.Id("com.experitest.ExperiBank:id/logoutButton")).Click();

            Thread.Sleep(5000);
            driver.Quit();
        }
    }
}

Thursday, 21 May 2015

Appium Java - Executing 'Appium-Webdriver' automation script on mobile device

This session demonstrates automating the script for 'EriBank' app and executing the automation script in mobile device.

Prerequisites(previous session):
Watch the video sessions in the below URL's
1. http://automation-home.blogspot.in/2015/05/appium-installation.html
2. http://automation-home.blogspot.com/2015/05/appium-overview-deviceversions-and-apilevels.html
3. http://automation-home.blogspot.com/2015/05/appium-uiautomatorviewer.html

Video Session covers below topics:
- Automating EriBank App
- Authoring script without using Junit/TestNG
- Capabilities
   * deviceName
   * platformVersion
   * app
      - capabilities.setCapability("app",System.getProperty("user.dir")+"/apk/EriBank.apk");
   * appPackage
   * appActivity
- AndroidDriver (in earlier version it is 'AppiumDriver')
   * driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
- Executing the automation script in the mobile device.

Sample Program:
package pack1;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

public class TestEriBank {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
        AppiumDriver driver;
     
        DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","");
//capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("app",System.getProperty("user.dir")+"/apk/EriBank.apk");

capabilities.setCapability("appPackage", "com.experitest.ExperiBank");
capabilities.setCapability("appActivity", ".LoginActivity");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

driver.findElement(By.id("com.experitest.ExperiBank:id/usernameTextField")).sendKeys("company");
driver.findElement(By.id("com.experitest.ExperiBank:id/passwordTextField")).sendKeys("company");
driver.findElement(By.id("com.experitest.ExperiBank:id/loginButton")).click();

driver.findElement(By.id("com.experitest.ExperiBank:id/logoutButton")).click();

Thread.sleep(3000);
driver.quit();
}
}

Note: 
   For executing the above program 'apk' folder should be created in the eclipse project and 'EriBank.apk' file should be placed in the 'apk' folder of the eclipse project.
   'Eribank.apk' can be downloaded from 'http://code.google.com/p/eribank/downloads/list'
 
Watch Demo

Friday, 15 May 2015

Appium

1. Appium Installation.
    http://automation-home.blogspot.com/2015/05/appium-installation.html

2. Appium overview, device versions and api levels. 
    http://automation-home.blogspot.com/2015/05/appium-overview-deviceversions-and-apilevels.html

3. Appium uiautomatorviewer.
    http://automation-home.blogspot.com/2015/05/appium-uiautomatorviewer.html

4. Enable 'Developer options' and 'USB debugging' on android mobile.
    http://automation-home.blogspot.com/2015/12/enable-developer-options.html

5. Installing 'EriBank' app in android device.
    http://automation-home.blogspot.com/2015/12/installing-eribank-app-in-android-mobile.html

6 Appium Java - Executing 'Appium-Java' automation script on real android mobile device.
    http://automation-home.blogspot.com/2015/05/appium-java-executing-appium-webdriver-script.html

7. Appium C# - Executing 'Appium-C#' automation script on real android mobile device.
    http://automation-home.blogspot.com/2015/05/appium-csharp-executing-script.html

8. Appium Python - Executing 'Appium-Python' automation script on real android mobile device.
    http://automation-home.blogspot.com/2015/12/python-executing-appium-script.html

9. Appium Protractor - Executing 'Appium-Protractor' automation script on real android mobile device.
    http://automation-home.blogspot.com/2015/12/execute-protractor-script-on-real-using-appium.html

10. Appium Java - Run appium script on real android device remotely through Wi-Fi
    http://automation-home.blogspot.com/2015/12/run-appium-script-on-real-android-device-through-wifi.html

11. Appium Java - Differences in executing the web automation script in Mobile and PC.
      http://automation-home.blogspot.com/2015/12/differences-in-executing-web-automation-script-in-mobile-and-pc.html

12. Mirror Android Phone to your computer using Androidscreencast.
     http://automation-home.blogspot.com/2015/12/androidscreencast.html

13. Android mobile automation - USB Troubleshooting
      http://automation-home.blogspot.com/2016/01/android-mobile-automation-USB-Troubleshooting.html

14. Appium Java - Performing Drag and Drop.
     
http://automation-home.blogspot.com/2016/01/java-appium-performing-drag-and-drop.html  

Appium - uiautomatorviewer

This session demonstrates inspecting/identifying the elements in the mobile device app.

Previous session:
 - Appium Overview, device versions and API Levels
   http://automation-home.blogspot.com/2015/05/appium-overview-deviceversions-and-apilevels.html

Video Session covers below topics:
Downloading and installing mobile device app(.apk file) in Android Device:
    - downloading app from Playstore.
    - downloading the app from mobile web browser.
        ex: Eribank app

Un-installing the the apps from the mobile device:
    - un-installing the app using Application Manager
    - un-installing the app using Playstore   
   
Inspecting the locators/elements in the mobile device app(.apk):        
    Prerequisites:
        Android SDK is installed.
        JAVA JDK Installed.
        Set the environment path for android sdk and java sdk.
        Mobile Device is connected to the PC.
        Developer options are activated in the mobile device.
        USB Debugging is enabled in the mobile device.
            http://automation-home.blogspot.in/2015/05/appium-installation.html   

Launching 'uiautomatorviewer'.   
    - Inspect the elements/objects in the mobile device app using 'uiautomatorviewer'.
    - If mobile app page changes, then you need to reload the mobile device view in the 'uiautomatorviewer'. 

Watch Demo

Thursday, 14 May 2015

Wednesday, 13 May 2015

Appium - Installation

Appium is an opensource test automation tool to work with native, hybrid and mobile web apps.

Appium Softwares: 
Below are the bunch of software's and configuration's need to be done to work with APPIUM automation tool.

1. JDK 

2. Download Eclipse IDE


4. Install Android SDK

5. Set the Environment variable for Android SDK.
6. Install Appium Server for windows os.

7. Download the Appium java client jar file.

8. Download the Selenium Webdriver java client jar file.

9. Install Phone Drivers

10. Enable Developer options in the mobile device.
11. Enable USB Debugging in Mobile Device.
    http://automation-home.blogspot.com/2015/12/enable-developer-options.html

Watch Demo

Saturday, 9 May 2015

WebdriverJS - JavaScript bindings for WebDriver

WebdriverJS is javascript bindings for webdriver, using WebdriverJS you can write the automation script in javascript and execute the Webdriver Javascript.

Prerequisite:
1. Node.js is alreaddy installed click 'http://automation-home.blogspot.in/2015/05/installing-nodejs-and-npm-on-windows.html' for node.js installation process.
2. 'Chromedriver.exe' can be downloaded from 'https://sites.google.com/a/chromium.org/chromedriver/downloads'
3. Set the 'Chromedriver.exe' in the PATH variable,
click the url 'http://www.computerhope.com/issues/ch000549.htm' for setting the PATH variable.

Steps for Executing the script developed using WebdriverJS:

Open the url 'https://code.google.com/p/selenium/wiki/WebDriverJs'

Save the copied javascript as 'SampleTest.js'.

Open the command prompt, navigate to the location where 'SampleTest.js' is present.
Run the command 'npm install selenium-webdriver' in the command prompt.

Run the command 'node SampleTest.js' in the command prompt.

Javascript 'SampleTest.js' is executed.

Watch Demo
Note:
Above post is older.
Webdriverjs is now deprecated,
Project is now called WebdriverIO(http://webdriver.io/). 

Monday, 4 May 2015

Installing Node.js and NPM on Windows

1. Download Node.js installer from https://nodejs.org/download


2. Run the installer (i.e. msi file )








Once installation is completed, restart your computer.
 
After your computer is restarted, check the Node.js and NPM versions by executing the below simple commands on Windows command prompt.

Test Node.js Version:
Type 'node -v' in command prompt and press enter key.


Test NPM Version:
Type 'npm -v' in command prompt and press enter key.

  

Print 'Hello world' in console.


Prerequisite:
Node.js and NPM is installed.

Add 'console.log('Hello world');' and save the file as 'Hello.js'


To run 'Hello.js', open the command prompt and navigate to folder location of 'Hello.js'.

In command prompt type 'node Hello.js' and press enter key.

Saturday, 2 May 2015

AutomationHomeMobile App for Mobile.

'Automation-Home blog' Mobile App view.


Link to download & install the mobile app.
http://app.appsgeyser.com/AutomationHomeMobile

Download and Install the 'AutomationHomeMobile' App to view the 'Automation-Home' blog updates. 

Friday, 1 May 2015

Javascript - Javascript reads JSON data and display in the HTML.


JSON data is displayed in the HTML:

Javascript reads the JSON data:


JSON File: 'Books.json'
{
    "books": [
        {
            "header_language": "Programming Language",
            "header_book_name": "Book Name",
            "header_seller": "Seller"
        },
        {
            "language": "Java",
            "book_name": "Java, A Beginner's Guide, 5th Edition",
            "seller": "Amazon.in"
        },
        {
           "language": "C#",
            "book_name": "Microsoft Visual C# 2013",
            "seller": "flipkart.com"
        }
    ]
}

Javascript File: 'Books.js'
   $(function() {
   $.getJSON('Books.json', function(data) {
       $.each(data.books, function(i, b) {
          if(b.header_language!=undefined && b.header_book_name!=undefined && b.header_seller!=undefined){
          var thlRow =     "<th>" + b.header_language + "</th>" +
                        "<th>" + b.header_book_name + "</th>" +
                        "<th>" + b.header_seller + "</th>" 
                       
           $(thlRow).appendTo("#bookdata thead");             
          }

       if(b.header_language==undefined && b.header_book_name==undefined && b.header_seller==undefined){      
       var tblRow =     "<tr>" +
                            "<td>" + b.language + "</td>" +
                            "<td>" + b.book_name + "</td>" +
                            "<td>" + b.seller + "</td>" +
                        "</tr>"
           $(tblRow).appendTo("#bookdata tbody");
       }
     });
   });
});

HTML file: 'TestJson.html'
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script type="text/javascript" src="Books.js"></script>
</head>

<body>
   <table id= "bookdata" border="2">
        <thead>
        </thead>
       
        <tbody>
        </tbody>
   </table>
</body>
</html>


Open the 'TestJson.html' file in Firefox browser:
 

Open the 'TestJson.html' file in Chrome browser:
 
JSON data is not displayed in the HTML file due to the Security setting of the chrome browser.
Chrome browser doesn't allow to read the data from files present in the system.

Check for the '--disable-web-security' of the chrome browser.
http://peter.sh/experiments/chromium-command-line-switches/

Open the command prompt.

Open the chrome browser with '--disable-web-security' parameter.
c:\progra~2\Google\Chrome\Application\chrome.exe --disable-web-security C:\Users\DELL1\Desktop\json\TestJson.Html 


Environment used  for executing the above JS, JSON, HTML: 
Operating System: Windows 8
Browser:
   - Firefox '33' version,
   - Google Chrome browser '42.0.2311.135' version

 

 

Above  .html, .js and .json files are re-written by making few minor changes and presented below.

 

JSON File: 'Books.json
 [
    {
        "header_language": "Programming Language",
        "header_book_name": "Book Name",
        "header_seller": "Seller"
    },
    {
        "language": "Java",
        "book_name": "Java, A Beginner's Guide, 5th Edition",
        "seller": "Amazon.in"
    },
    {
       "language": "C#",
        "book_name": "Microsoft Visual C# 2013",
        "seller": "flipkart.com"
    }
]

Javascript File: 'Books.js'
var jsonFile = 'Books.json';
  $(function() {
   $.getJSON(jsonFile, function(data) {
       $.each(data, function(i, b) {
          if(b.header_language!=undefined && b.header_book_name!=undefined && b.header_seller!=undefined){
          var thlRow =     "<th>" + b.header_language + "</th>" +
                        "<th>" + b.header_book_name + "</th>" +
                        "<th>" + b.header_seller + "</th>" 
                       
           $(thlRow).appendTo("#bookdata thead");             
          }

       if(b.header_language==undefined && b.header_book_name==undefined && b.header_seller==undefined){      
       var tblRow =     "<tr>" +
                            "<td>" + b.language + "</td>" +
                            "<td>" + b.book_name + "</td>" +
                            "<td>" + b.seller + "</td>" +
                        "</tr>"
           $(tblRow).appendTo("#bookdata tbody");
       }
     });
   });
});

HTML file: 'TestJson.html'
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script type="text/javascript" src="Books.js"></script>
</head>

<body>
   <table id= "bookdata" border="2">
        <thead>
        </thead>
       
        <tbody>
        </tbody>
   </table>
</body>
</html>