TESTEVERYTHING

Wednesday 17 December 2014

Mac terminal cursor commands

·         Meta-d to delete a word starting from the current cursor position
·         Ctrl-a to jump to start of the line
·         Ctrl-e to jump to end of the line
·         Ctrl-k to kill the line starting from the cursor position
·         Ctrl-y to paste text from the kill buffer
·         Ctrl-r to reverse search for commands you typed in the past from your history
·         Ctrl-s to forward search (works in zsh for me but not bash)
·         Ctrl-f to move forward by a char

·         Ctrl-b to move backward by a char

Automation Testing of Android app on device using Appium


1)      Run the setup using the below provided location using the URL as :
and click on installer_r24.0.1-windows.exe for windows.

2)      Agree to the terms of service and licence from google and download the installer.
3)      Download the Appium for windows latest version from http://appium.io/ .
4)      Download java-client version for the same latest from location http://appium.io/downloads.html
5)      Set ANDROID_HOME as environment variable providing the path for the SDK till the SDK path
6)      Set the path for platform tools and tools folder specifically like below :
D:\Mobiletesting\MobileSDK\sdk\platform-tools;D:\Mobiletesting\MobileSDK\sdk\tools;




7)      Once the path for tools and platform-tools is set check if the configurations are correct by opening the command prompt and entering the command as
adb devices
If the configurations are correct then the device will be listed as a result of the response for command as above in the screen.
List of devices attached
ZX1B32DBJ3      device
Here ZX1B32DBJ3       is the device connected to the 32 bit machine having SDK setup.
8)      Have an apk file of the application to be tested ready and open appium.exe by running the utility for launching the appium window.
9)      Configure Appium like in the below screenshot :
Application path: Path for the apk file to be tested.
Other fields such as package,launch activity platform version ,automation name,device name all fields will be populated by default.
 
Click on start the appium node server button at the right corner of the window and we can see the below mentioned activity listed when the server is launched.
 
Create a java project using the Android eclipse toolkit and set the properties such as below.

package com.testng;

import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

public class  WhatsApp {


WebDriver dr;
   
@Test
public void testApp() throws Exception
{
    //WebDriver dr;
    String contact ="shreekantpandey@gmail.com";
    File app = new File("D:\\Mobiletesting\\WhatsApp.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName","Chrome");
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");
    //capabilities.setCapability("app",app.getAbsolutePath());
    //capabilities.setCapability("appPackage","com.testng");
    //capabilities.setCapability("appActivity","com.testng.WhatsApp");
   
    dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
   
    dr.get("http://www.apple.com");
   
    dr.quit();

   
}
@AfterClass
public void teardown(){
    //close the app
    dr.quit();
}
}



Where details specific to device and platform are :

DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName","Chrome");
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");


and driver are :

dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);


Once we have the browser handle we can navigate to any page of our choice like the content here being navigated to
dr.get("http://www.apple.com");

___________________________________________________


2. For Android application related project creation having a launching activity are:
package com.testng;

import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.junit.AfterClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class  NewClass {


WebDriver dr =null;
   
@BeforeMethod
public void setup() throws Exception

{
     File appDir = new File("D://Mobiletesting");
     File app = new File(appDir, "MakeMyTrip_Flights_Hotels_Bus.apk");
     
     
     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability("app-package", "com.makemytrip");
     capabilities.setCapability("app-wait-activity", "com.mmt.ui.activity.Splashactivity");
     capabilities.setCapability("app-activity", "com.mmt.ui.activity.Splashactivity");
  
    capabilities.setCapability("deviceName","ZX1B32DBJ3");
    capabilities.setCapability("platformVersion","4.4");
    capabilities.setCapability("platformName", "Android");
  
   
    //capabilities.setCapability("browserName","Chrome");

    //capabilities.setCapability("app-activity","com.mmt.ui.activity.Splashactivity");
//    capabilities.setCapability("app",app.getAbsolutePath());
//    capabilities.setCapability("appPackage","com.makemytrip");

   
    dr= new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
   
}
@Test
public void loginTest() throws Exception {
    String text;   
    Thread.sleep(5000);

       
     
      dr.findElement(By.className("android.widget.Button")).click();
     
      dr.findElement(By.id("com.makemytrip:id/login_activity_emailId_edt")).sendKeys("shreekant1282@gmail.com");
      dr.findElement(By.id("com.makemytrip:id/login_activity_password_edt")).sendKeys("3093005");
      //dr.findElement(By.id("id/login_activity_password_edt")).sendKeys("3093005");
      dr.findElement(By.id("com.makemytrip:id/login_activity_login_btn")).click();
      WebDriverWait wait = new WebDriverWait(dr,80);
      text = dr.findElement(By.className("android.widget.TextView")).getText();
      if (text.equals("User not valid!"))
      {
          System.out.println("test passed");
      }
      else
      {
          System.out.println("test failed");
      }
      //dr.quit();

      }
@AfterTest
public void teardown(){
    //close the app
    dr.quit();
    //dr.close();
}
}

Where details are for same device but with different .apk file having different launching activity as in the screenshot below.




Sample makemytrip.apk file can be downloaded from anywhere over the internet.


    

Wednesday 26 November 2014

Calabash iOS installation steps

1.  calabash

1.1            Software Requirement

1.       Xcode 6.1 (Mandatory for iOS 8.1)
2.       RVM
3.       Ruby  2.1 > version 2.0
4.       Homebrew
5.       Java
6.       Maven
7.       Ant
8.       Cocoapods

1.2            Install Xcode

1.       Download the latest Xcode from apple developer site


1.3             Install RVM

1. Open the terminal window on mac
 $ \curl -sSL https://get.rvm.io | bash -s stable
           
            Refer the below url for more info
                               
http://rvm.io/rvm/install

1.4            Install Ruby

2.       Ruby is installed by default on Mac, just make sure it is using the version 2.0.0, ruby version can be checked using command;
                                                $ ruby -v
                        Refer below link to update ruby

1.5             Install HomeBrew

1.    Homebrew, “the missing package manager for OS X,” allows you to easily install hundreds of open-source tools. The full instructions are available on the Homebrew Wiki, but you should only need to run the command that’s listed at the bottom of the Homebrew site:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.   Once the installation is successful, run the following command:
$ brew doctor

1.6            Install Calabash-cucumber

$ gem install calabash-cucumber

1.7            Install Cocapods

$ gem install cocoapods

1.8            Install Java, Maven, Ant & Ideviceinstaller

1.    Download java .dmg file from http://www.java.com/en/download/
2.    Double click .dmg file and install java
3.    Now download maven from http://www.interior-dsgn.com/apache/maven/maven-3/3.2.1/binaries/apache-maven-3.2.1-bin.tar.gz
4.    Extract maven to any directory
5.    Now to set the environment variables, in the terminal type
$ nano ~/.bash_profile
For Java enter;
      export JAVA_HOME= <path to your java directory >
For Maven enter;
      export M2_HOME= <path to your extracted maven directory>
      export M2=$M2_HOME/bin


Once done press ctrl+O and press enter, now press ctrl+x
6.    In the same terminal enter command
$ source ~/.bash_profile
7.    To install Ant use command
 $ brew install ant
8.    To verify the Maven installation, in terminal, issue the command mvn -version.

$ mvn -version

Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /usr/share/maven
Java version: 1.6.0_33, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.4", arch: "x86_64", family: "mac"
9.    To verify java installation, in terminal, issue the command mvn -version.

$ java –version

10.  To install iDeviceinstaller.

$ brew uninstall ideviceinstaller

Tuesday 25 November 2014

Calabash-iOS commands

irb(main):021:0> query("label all",:text)
[
    [ 0] "Home",
    [ 1] "Pull down to refresh",
    [ 2] "FTSE",
    [ 3] "6739.27*",
    [ 4] "+0.14%",
    [ 5] "+9.48",
    [ 6] "DAX",
]

irb(main):023:0>  query("button index:0").first.keys
[
    [0] "selected",
    [1] "enabled",
    [2] "rect",
    [3] "id",
    [4] "description",
    [5] "label",
    [6] "alpha",
    [7] "class",
    [8] "frame"
]
irb(main):024:0>  query("button index:0").first.values
[
    [0] false,
    [1] true,
    [2] {
        "center_x" => 25,
               "y" => 26,
           "width" => 20,
               "x" => 15,
        "center_y" => 37,
          "height" => 22
    },
    [3] nil,
    [4] "<ButtonMostTappable: 0x1673a670; baseClass = UIButton; frame = (15 26; 20 22); opaque = NO; layer = <CALayer: 0x16736f80>>",
    [5] "ThreeLines",
    [6] 1,
    [7] "ButtonMostTappable",
    [8] {
             "y" => 26,
         "width" => 20,
             "x" => 15,
        "height" => 22
    }
]
irb(main):025:0> query("button index:0").first["frame"]["x"]
15


irb(main):026:0> classes("view")
[
    [ 0] "UIWindow",
    [ 1] "UIView",
    [ 2] "UIView",
    [ 3] "MMDrawerCenterContainerView",
    [ 4] "UIView",
    [ 5] "UIImageView",
    
]
irb(main):027:0> classes("*")
[
    [ 0] "UIWindow",
    [ 1] "UIView",
    [ 2] "UIView",
    [ 3] "MMDrawerCenterContainerView",
    [ 4] "UIView",
    [ 5] "UIImageView",
    [ 6] "UIView",
]
irb(main):028:0> classes("UIImageView").count
13
uia_tap_mark "header search"
uia_type_string "Appl"
query("view:'UITableViewCellContentView' label", :text)
query("*", :accessibilityLabel)
query("button", :accessibilityLabel)
query("label all",:text)
uia_tap_mark "ThreeLines"
uia_tap_mark "Create New Watchlist"
uia_type_string "QA_Test_List"
uia_tap_mark "Done"
touch("view:'UISearchBarTextField'")
uia_type_string "Appl"
uia_tap_mark "Apple Inc (AAPL)"
query("view:'UILabel'{accessibilityLabel ENDSWITH 'EUROPE'}")
[
    [0] {
               "text" => "EUROPE",
            "enabled" => true,
               "rect" => {
            "center_x" => 160.25,
                   "y" => 396,
               "width" => 43.5,
                   "x" => 138.5,
            "center_y" => 404,
              "height" => 16
        },
                 "id" => nil,
        "description" => "<UILabel: 0x17f57720; frame = (138.5 3; 43.5 16); text = 'EUROPE'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x17d99ea0>>",
              "label" => "EUROPE",
              "alpha" => 1,
              "class" => "UILabel",
              "frame" => {
                 "y" => 3,
             "width" => 43.5,
                 "x" => 138.5,
            "height" => 16
        }
    }
]
query("view:'UILabel'{accessibilityLabel BEGINSWITH 'EUROPE'}")
[
    [0] {
               "text" => "EUROPE",
            "enabled" => true,
               "rect" => {
            "center_x" => 160.25,
                   "y" => 396,
               "width" => 43.5,
                   "x" => 138.5,
            "center_y" => 404,
              "height" => 16
        },
                 "id" => nil,
        "description" => "<UILabel: 0x17f57720; frame = (138.5 3; 43.5 16); text = 'EUROPE'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x17d99ea0>>",
              "label" => "EUROPE",
              "alpha" => 1,
              "class" => "UILabel",
              "frame" => {
                 "y" => 3,
             "width" => 43.5,
                 "x" => 138.5,
            "height" => 16
        }
    }
]
query("view {text BEGINSWITH 'EUROPE'}")
[
    [0] {
               "text" => "EUROPE",
            "enabled" => true,
               "rect" => {
            "center_x" => 160.25,
                   "y" => 396,
               "width" => 43.5,
                   "x" => 138.5,
            "center_y" => 404,
              "height" => 16
        },
                 "id" => nil,
        "description" => "<UILabel: 0x15f78910; frame = (138.5 3; 43.5 16); text = 'EUROPE'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15f789d0>>",
              "label" => "EUROPE",
              "alpha" => 1,
              "class" => "UILabel",
              "frame" => {
                 "y" => 3,
             "width" => 43.5,
                 "x" => 138.5,
            "height" => 16
        }
    }
]
touch("view {text BEGINSWITH 'EUROPE'}")
[
    [0] {
               "text" => "EUROPE",
            "enabled" => true,
               "rect" => {
            "center_x" => 160.25,
                   "y" => 396,
               "width" => 43.5,
                   "x" => 138.5,
            "center_y" => 404,
              "height" => 16
        },
                 "id" => nil,
        "description" => "<UILabel: 0x15f78910; frame = (138.5 3; 43.5 16); text = 'EUROPE'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15f789d0>>",
              "label" => "EUROPE",
              "alpha" => 1,
              "class" => "UILabel",
              "frame" => {
                 "y" => 3,
             "width" => 43.5,
                 "x" => 138.5,
            "height" => 16
        }
    }
]
touch("view {text CONTAINS 'EUROPE'}")
[
    [0] {
               "text" => "EUROPE",
            "enabled" => true,
               "rect" => {
            "center_x" => 160.25,
                   "y" => 396,
               "width" => 43.5,
                   "x" => 138.5,
            "center_y" => 404,
              "height" => 16
        },
                 "id" => nil,
        "description" => "<UILabel: 0x15f78910; frame = (138.5 3; 43.5 16); text = 'EUROPE'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x15f789d0>>",
              "label" => "EUROPE",
              "alpha" => 1,
              "class" => "UILabel",
              "frame" => {
                 "y" => 3,
             "width" => 43.5,
                 "x" => 138.5,
            "height" => 16
        }
    }
]

Swipe the table view cell

for left direction move:

swipe(:left,{:query => "UITableView index:0 tableViewCell indexPath:0,3"})

here 0 refer to row and 3 section

You hav to try with different combination like 0,1 or 0,2


for right direction move:

swipe(:right,{:query => "UITableView index:0 tableViewCell indexPath:0,3"})

here 0 refer to row and 3 section

You hav to try with different combination like 0,1 or 0,2


Swipe using two fingers



def swipeDirectionTwoFingers(text)

if text.eql?("left") 



uia('target.dragInsideWithOptions({touchCount:2, startOffset:{x:1.0, y:0.1}, endOffset:{x:0.1, y:0.1}, duration:1.5})')


end

if text.eql?("right")

uia('target.dragInsideWithOptions({touchCount:2, startOffset:{x:0.1, y:0.1}, endOffset:{x:1.0, y:0.1}, duration:1.5})')

end


end



query("* marked:'1d' parent * index:0",:backgroundColor)


if you discover that an element uses the class UIView, you can click in correspondent class and discover the list of attributes/properties that you can search for. Example:
- :backgroundColor
- :hidden
- :alpha
- :opaque
- :maskView
- :layer
- :accessibilityLabel
In Android the Views (also the TextView) can have almost anything as a background not just a color (a bitmap, a shape, a gradient color, etc). Because of this there is no way to get the background color of a view (it is not stored).
There is a simple form of specifying classes. For example, if you just write button this matches all views which have a class with simple name “button” (or “Button” as this is case in-sensitive). Remember that the simple name of a class is the last segment of the fully qualified class name, e.g., for android.widget.Button it is Button
This is not a limitation of Calabash but the Android system. You can get any property of an Android view if it is accessible.
The property names map to “getter”-methods of the view objects. In general prop:valwill try to call:
  • prop()
  • getProp()
  • isProp()
You can query the following colors on the TextView (nothing is background):
- text color :currentTextColor
- hintTextColor :hintTextColor
- highlight color :highlightColor
- shadow color :shadowColor
You can identifying the properties of the class if you open the project and open the class file that you want to know the attributes. There you can find the properties that you can filter with calabash too.
- Examples:
Radio:
query("RadioButton id:'radio_male'",:setChecked=>true)
query("RadioButton id:'radio_male'",:setChecked=>0)
Check:
query("CheckBox id:'check_update'",:isChecked)
query("CheckBox id:'check_update'",:isChecked=>1)
query("CheckBox id:'check_update'",:checked)
query("CheckBox id:'check_update'",:setChecked=>true)

Progress Bar:
query("RatingBar",setProgress:4)
query("RatingBar",:setProgress=>4)
query("RatingBar",:getProgress)
query("RatingBar",:method_name=>'getProgress', :arguments=>[])
query("RatingBar",:method_name=>'setProgress', :arguments=>[5])
Date:
query("datePicker",:method_name =>'updateDate',:arguments =>[1990,11,30])
Text:
query("EditText id:'email_input'",:getText)
query("EditText id:'email_input'",:text)
query("EditTextid:'email_input'", :method_name=>'setText',:arguments=>['test@test.com'])
query("EditTextid:'email_input'", :method_name=>'getText',:arguments=>[])

indexPath: A special construct that supports selecting cells in UITableViews by index path. The general form is:
"tableViewCell indexPath:row,sec"
where row is an number describing the row of the cell, and sec is a number describing its section.
In general, you can filter on any selector which returns a simple result like a number, string or BOOL.
"button isEnabled:1"
iOS Directions:
There are four directions descendant, child, parent and sibling. These determines the direction in which search proceeds.
Both descendant and child looks for subviews inside a view. The difference is that descendant keep searching down in the sub-view’s subviews, whereas child only looks down one level. The direction sibling searches for views that are “at the same level” as the present view (this is the same as: first find the immediate parent, then find all subviews except for the view itself).By default the direction is descendant, which intuitively means “search amongst all subviews (or sub-views of sub-views, etc).” But you can change the traversal direction. Here is an advanced example:

query("label marked:'Tears in Heaven' parent tableViewCell descendant tableViewCellReorderControl")



Which one is right ?

Translate







Tweet