Monday, 6 June 2016

Maven setup for selenium



1)Set JAVA_HOME from environment variable(My computer -advanced setting)

2) add to path which added as JAVA_HOME till bin folder

3) Download ANT from Apache maven website, go for "bin" version for maven

4) unzip folder

5) set MAVEN_HOME and M2_HOME from advance setting

6) add to path which added as MAVEN_HOME till bin folder

7) go to cmd check mvn -version (verify maven install it proper or not)

8) If 7th step failed, then you are wrong with enviorment setting or java version

9) go to eclipse, add new software->http://download.eclipse.org/technology/m2e/releases as maven

10) go to project , right click and configure as maven

11) now go to project-pom.xml add dependancy as per your need, eg below dependancy for latest selenium jars

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency> 

So this is how you can add maven to your selenium project

Sunday, 5 June 2016

iphone and android crash log

Getting Crash Logs Directly From a Device Without Xcode
Your users can retrieve crash reports from their device and send them to you via email by following these instructions.
(It is not possible to get device console logs directly from a device)
1) Open Settings app
2) Go to Privacy, then Diagnostics & Usage
3) Select Diagnostics & Usage Data
4) Locate the log for the crashed app. The logs will be named in the format:
5) Select the desired log. Then, using the text selection UI select the entire text of the log. Once the text is selected, tap Copy
6) Paste the copied text to Mail and send to an email address as desired Getting Crash Logs and Console Output From a Device Using Xcode
Even though you won't be able to run the app in Xcode's debugger, Xcode can still give you all the information you need to debug the problem. Using Xcode 6
1) Plug in the device and open Xcode
2) Choose Window -> Devices from the menu bar
3) Under the DEVICES section in the left column, choose the device
4) To see the device console, click the up-triangle at the bottom left of the right hand panel
5) Click the down arrow on the bottom right to save the console as a file
6) To see crash logs, select the View Device Logs button under the Device Information section on the right hand panel
7) Find your app in the Process column and select the Crash log to see the contents.
8) To save a crash log, right click the entry on the left column and choose "Export Log"
9) Xcode 6 will also list low memory logs here. These will be shown with a Process name "Unknown" and Type "Unknown". You should examine the contents of these logs to determine whether any of these are caused by your app. For more information about low memory logs, see Understanding and Analyzing iOS Application Crash Reports. Using Xcode 5
1) Plug in the device and open Xcode
2) Open the Organizer window and select the Devices tab
3) Under the DEVICES section in the left column, expand the listing for the device
4) Select Device Logs to see crash logs or select Console to see Console output Back to Top Enabling App Store Diagnostic Reporting
Crash logs are automatically collected from customers who have opted in to sending diagnostic and usage information to Apple.
Beginning with Xcode 6.3, crash logs from App Store customers running at least iOS 8.3 and TestFlight beta testers can be found in the Xcode Organizer. To obtain these crash logs:
1) Open the Organizer window in Xcode 6.3 and above
2) Select "Crashes" at the top. The available crash logs can then be found within this window.
The App Distribution Guide contains further information about the Crash Reporting service.
Crash reports from customers running older iOS versions may be found in iTunes Connect.
If someone is reporting a crash, and you do not see a corresponding report in iTunes Connect, you should direct them to the following knowledge base articles for Mac or for Windows so they can opt-in to sending you crash reports.

for android -user can use monitor file from sdk folder else using adb logcat he can check logs in command prompt

appium swipe by text and appium jars

swipe by text- scorllToExact is function 1 can use for swipe- driver.scrollToExact("text")


Appium jars-http://mvnrepository.com/artifact/io.appium/java-client/2.1.0

only 1 jar needed for appium named -java-client

Thursday, 2 June 2016

compile error come when user import project in eclipse

for this situation , user should add libraries from properties, same like adding jars

network connection using appium-interruptive testing

The Selenium Mobile JSON Wire Protocol Specification supports an API for getting and setting the network connection for a device. The API works through a bitmask, assigning an integer to each possible state:
Value (Alias) Data Wifi Airplane Mode
0 (None) 0 0 0
1 (Airplane Mode) 0 0 1
2 (Wifi only) 0 1 0
4 (Data only) 1 0 0
6 (All network on) 1 1 0

iOS

Unfortunately, at the moment Appium does not support the Selenium network connection API for iOS.

Android

Choose the setting you would like to use, and then send the correct bitmask from the table above.
// javascript
// set airplane mode
driver.setNetworkConnection(1)

// set wifi only
driver.setNetworkConnection(2)

// set data only
driver.setNetworkConnection(4)

// set wifi and data
driver.setNetworkConnection(6)

Sunday, 22 May 2016

differencce between mobile and web app testing

What the difference between web testing and mobile
application testing
Question Submitted By :: Mobile Testing
I also faced this Question!! Answer Posted By
Answers were Sorted based on User's Feedback
Answer
# 1 Jotted some of the test coverage we need to focus on mobile testing which differed from web testing.

1. Interrupts : How app responds when it has interrupted by calls,SMS,alerts or Wi-fi change when the app is running.App should regain it's state after the interruption.

2.Mobile apps execute on the limited hardware resources and make sure that there is no hangups or performance issues.

3.Cross platform and cross devices :
App should be tested on different OS and Different devices for same issue(Android: MOTO G,Nuxes etc)

4.UI components loading,component locations while device is in different orientations.

5. Push notifications : Mobile apps works on push notifications whereas pc web applications doesn't have such concept.

6. Crash scenarios also need to be taken care when app is running.

Thursday, 19 May 2016

string function

String userInput = "Hello, World! ssss1££$$%%##";
    //    String onlyAlphaNumeric = userInput.replaceAll("[^a-zA-
Z0-9]", "");
       
        //only num
    //String onlyAlphaNumeric = userInput.replaceAll("[^0-9]", "");
        //num and alpabets
                String onlyAlphaNumeric = userInput.replaceAll("[^a-zA-Z0-9]", "");           
        System.out.println(onlyAlphaNumeric);

Saturday, 14 May 2016

desire capabilities appium

Capability Description Values
automationName Which automation engine to use Appium (default) or Selendroid
platformName Which mobile OS platform to use iOS, Android, or FirefoxOS
platformVersion Mobile OS version e.g., 7.1, 4.4
deviceName The kind of mobile device or emulator to use iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc…
app The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these. Appium will attempt to install this app binary on the appropriate device first. Note that this capability is not required for Android if you specify appPackage and appActivity capabilities (see below). Incompatible with browserName. /abs/path/to/my.apk or http://myapp.com/app.ipa
browserName Name of mobile web browser to automate. Should be an empty string if automating an app instead. ‘Safari’ for iOS and ‘Chrome’, ‘Chromium’, or ‘Browser’ for Android
newCommandTimeout How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session e.g. 60
autoLaunch Whether to have Appium install and launch the app automatically. Default true true, false
language (Sim/Emu-only) Language to set for the iOS Simulator e.g. fr
locale (Sim/Emu-only) Locale to set for the iOS Simulator e.g. fr_CA
udid Unique device identifier of the connected physical device e.g. 1ae203187fc012g
orientation (Sim/Emu-only) start in a certain orientation LANDSCAPE or PORTRAIT

appium code for rotation

  • //Launch the application
  • driver.rotate(landscape);
  • //Perform some desired actions and again switch to portrait mode
  • driver.rotate(portrait);
  • //Continue the test
  • //Launch the application
  • driver.rotate(landscape);
  • //Perform some desired actions and again switch to portrait mode
  • driver.rotate(portrait);
  • //Continue the test
  • - See more at: http://findnerd.com/list/view/How-to-perform-the-screen-rotation-in-Appium-/12414/#sthash.9vr05rZG.dpuf
  • //Launch the application
  • driver.rotate(landscape);
  • //Perform some desired actions and again switch to portrait mode
  • driver.rotate(portrait);
  • //Continue the test
  • - See more at: http://findnerd.com/list/view/How-to-perform-the-screen-rotation-in-Appium-/12414/#sthash.9vr05rZG.dpuf
  • //Launch the application
  • driver.rotate(landscape);
  • //Perform some desired actions and again switch to portrait mode
  • driver.rotate(portrait);
  • //Continue the test
  • - See more at: http://findnerd.com/list/view/How-to-perform-the-screen-rotation-in-Appium-/12414/#sthash.151w8far.dpuf
  • //Launch the application
  • driver.rotate(landscape);
  • //Perform some desired actions and again switch to portrait mode
  • driver.rotate(portrait);
  • //Continue the test
  • - See more at: http://findnerd.com/list/view/How-to-perform-the-screen-rotation-in-Appium-/12414/#sthash.151w8far.dpuf

    Tuesday, 16 February 2016

    Table value selection from objetcs

    Below is HTML

    <tbody>
    </table>
    </td>
    </tr>
    <tr>
    <td>
    <div id="divListView" style="width: 100%; height: 300px; overflow: auto; display: block;">
    <table id="tblListView" class="adminlist" cellspacing="1" cellpadding="0" style="table-layout: fixed; width: 100%;">
      <tbody data-bind="template: { name: 'ActiveGradeTemplate', foreach: ActiveGrade }">
        <tr class="row0">
          <td data-bind="text:$index()+1" style="width: 5%;">1</td>
          <td data-bind="text: GradeName" style="width: 20%;">Vantage Point</td>
          <td align="right" data-bind="text: DisplayCreatedDate" style="width: 10%;">27 Mar 2013</td>
          <td align="right" data-bind="text: CreatedByUser" style="width: 10%;">Name</td>
          <td align="right" data-bind="text: DisplayModifiedDate" style="width: 10%;">27 Mar 2013</td>
          <td align="right" data-bind="text: ModifiedByUser" style="width: 10%;">Name</td>
          <td align="center" data-bind="text: Status" style="width: 5%;">Active</td>
          <td align="center" style="width: 10%;">
            <a id="lnkEdit_7" data-bind="click: $root.lnkEdit, attr:{'id':'lnkEdit_' + GradeID}" href="#">Edit</a>
            <span id="spanEdit_7" data-bind="attr:{'id':'spanEdit_' + GradeID}"></span>
          </td>
       </tr>
       <tr class="row0">
         <td data-bind="text:$index()+1" style="width: 5%;">2</td>
         <td data-bind="text: GradeName" style="width: 20%;">test grade</td>
         <td align="right" data-bind="text: DisplayCreatedDate" style="width: 10%;">Yesterday</td>
         <td align="right" data-bind="text: CreatedByUser" style="width: 10%;">Name</td>
         <td align="right" data-bind="text: DisplayModifiedDate" style="width: 10%;">Yesterday</td>
         <td align="right" data-bind="text: ModifiedByUser" style="width: 10%;">Name</td>
         <td align="center" data-bind="text: Status" style="width: 5%;">Active</td>
         <td align="center" style="width: 10%;">
           <a id="lnkEdit_11" data-bind="click: $root.lnkEdit, attr:{'id':'lnkEdit_' + GradeID}" href="#">Edit</a>
          <span id="spanEdit_11" data-bind="attr:{'id':'spanEdit_' + GradeID}"></span>
        </td>
      </tr>






    Below is code to retrieve data from tables

    // Grab the table 
    WebElement table = driver.findElement(By.id("divListView")); 
    
    // Now get all the TR elements from the table 
    List<WebElement> allRows = table.findElements(By.tagName("tr")); 
    
    // And iterate over them, getting the cells 
    for (WebElement row : allRows) { 
        List<WebElement> cells = row.findElements(By.tagName("td")); 
    
        // Print the contents of each cell
        for (WebElement cell : cells) { 
            System.out.println(cell.getText());
        }
    }


    Thursday, 4 February 2016

    DB connection from selenium

    • In order to test Database using Selenium you need to
      1. Make a connection to the Database
      2. Send Queries to the Database
      3. Process the results
    • The Syntax to connect to Database is
      • DriverManager.getConnection(URL, "userid", "password" )
    • You will also need the Statement Object to send queries
      • Statement stmt = con.createStatement();
    • To send the query to database use execute query and store the results in the ResultSet object
      • ResultSet rs = stmt.executeQuery(select * from employee;);
    • Java provides lots of built-in methods to process the SQL Output using the ResultSet Object

    Friday, 8 January 2016

    Appium with multiple device android

    The following code will help you.
    //Running multiple emulators from single appium server



    public class Test{
    
        WebDriver driver = null;
        int timeOut=180;
        int port=-1;
    
        Test(int port){
            this.port=port;
        }
    
        public void testEmulator(int p) throws Exception {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
            capabilities.setCapability(CapabilityType.VERSION, "4.3");
            capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
    
            capabilities.setCapability("udid","emulator-"+p);
    
            capabilities.setCapability("app-package", "your.app.pkg");
            capabilities.setCapability("app-activity",
                "your.app.pkg.Activity");
            driver = new RemoteWebDriver(new URL("http://127.0.0.1:"+this.port+"/wd/hub"),
            capabilities);
            driver.manage().timeouts().implicitlyWait(timeOut, TimeUnit.SECONDS);
            Thread.sleep(50000);
        }
    
        public void tearDown() {
            if (driver != null)
                driver.quit();
        }
    
        public void runTest() {
            try {
                testEmulator(5554);     // for emulator on port 5554
                tearDown();
                testEmulator(5556);     // for emulator on port 5556
                tearDown();
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        public static void main(String[] args) {
            new Test(4723).runTest();       // appium server port 4723
        }
    }

    Wednesday, 6 January 2016

    appium windows setup

    1. Install JAVA (jdk 6 or more)

    2. Set java in the class path, its weird but strictly follow this:
    For Windows 7: my computer ->right click--> properties--> advanced system settings-->environment variable--> create a new variable under system variable [not user variable], name it 'JAVA_HOME' and give path till java's directory
    example: C:\Program Files\Java\jdk1.6.0_27
    now open 'path' variable and add @ end of it ';%JAVA_HOME%\bin'
    Test it : go to cmd and type 'java' or 'jvm', it should echo some message but not 'command not found'

    3. Download android sdk for Android
    Adt: http://developer.android.com/sdk/index.html 4. Set the adb path in class path,
    For Windows : like java, create a new variable under system variable, name it "ANDROID_HOME" and give path till adb
    example: D:\Software\Android\android-sdk\
    now open 'path' variable and add @ end of it ';%ANDROID_HOME%\platform-tools' same for tools
    Test it : go to cmd and type 'adb', it should echo some message but not 'command not found'

    5. Download Appium
    For windows: AppiumForWindows-1.2.0.1.zip from https://bitbucket.org/appium/appium.app/downloads/



    6. If using eclipse open it and add adt plugin
    Top menu--> Help--> install new software --> add with name 'ADT' and site 'http://dl-ssl.google.com/android/eclipse/'
    and set the sdk path in eclipse in preferences-->Android [ which we had downloaded ]

    Wednesday, 30 December 2015

    hash map and hash table difference

    Difference between HashMap and HashTable / HashMap vs HashTable 

    1. Synchronization or Thread Safe :  This is the most important difference between two . HashMap is non synchronized and not thread safe.On the other hand, HashTable is thread safe and synchronized.
    When to use HashMap ?  answer is if your application do not require any multi-threading task, in other words hashmap is better for non-threading applications. HashTable should be used in multithreading applications.

    2. Null keys and null values :  Hashmap allows one null key and any number of null values, while Hashtable do not allow null keys and null values in the HashTable object.



    3. Iterating the values:  Hashmap object values are iterated by using iterator .HashTable is the only class other than vector which uses enumerator to iterate the values of HashTable object.



    HashMapHashtable



    SynchronizedNoYes



    Thread-SafeNoYes



    Null Keys and Null valuesOne null key ,Any null valuesNot permit null keys and values



    Iterator typeFail fast iteratorFail safe iterator



    PerformanceFastSlow in comparison



    Superclass and LegacyAbstractMap , NoDictionary , Yes

    Tuesday, 29 December 2015

    snapshot for reporting

     // Function call when test step FAILS
        public static void takeSnapshot(String msg,int status,WebDriver driver)
        {
            universalImageCounter++;
                String tempImgFile=IMG_PATH_UNDER_PARENT+"screenshot_"+(universalImageCounter)+".png";           
                try
                {
                    File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                    FileUtils.copyFile(srcFile, new File(tempImgFile));
                    addToReport("###"+msg, status);
                }
                catch(Exception ex)
                {
                        addToReport("Error ID 1: Issue while taking snapshot.",FAIL);
                }
        }

    Swipr issue while X and Y axis distance less than 50

    try{
        List<WebElement> el=driver.findElements(xpath);
        System.out.println("No of elements: "+el.size());
        int a,b,c;
        element=(MobileElement)el.get(0);
        int topY = element.getLocation().getY();
        int bottomY = topY + element.getSize().getHeight();
        int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2);
       
        /*if(topY<0){
            element=(MobileElement)el.get(1);
        topY = element.getLocation().getY();
        bottomY = topY + element.getSize().getHeight();
        centerX = element.getLocation().getX() + (element.getSize().getWidth()/2);
        }*/
        if(topY<0)
            topY=50;
        if(bottomY>driver.manage().window().getSize().height)
        bottomY=driver.manage().window().getSize().height-50;
    //    System.out.println("topY="+topY);
    //    System.out.println("bottomY="+bottomY);
    //    System.out.println("centerX="+centerX);
        driver.swipe(centerX, bottomY, centerX, topY, duration);
        if (bottomY-topY<=50){
            bottomY=driver.manage().window().getSize().height-50;
            topY=bottomY-50;
        }   
        driver.swipe(centerX, bottomY, centerX, topY, duration);
           
       
        }catch(Exception e){
            System.out.println("Exception occurred while swipeing up");
        }

    Wednesday, 2 December 2015

    enhanced for loop

    enhanced for loop is a simpler way to do this same thing. (The colon in the syntax can be read as "in.")
    for (int myValue : myArray) {
        System.out.println(myValue);
    }
    The enhanced for loop was introduced in Java 5 as a simpler way to iterate through all the elements of a Collection (Collections are not covered in these pages). It can also be used for arrays, as in the above example, but this is not the original purpose.
    Enhanced for loops are simple but inflexible. They can be used when you wish to step through the elements of the array in first-to-last order, and you do not need to know the index of the current element. In all other cases, the "standard" for loop should be preferred.
    Two additional statement types, break and continue, can also control the behavior of enhanced for loops.

    Comparing Array and list of array

     public Mobile_AboutMePage verifyaboutMeScreen() throws IOException, InterruptedException{
           
            //expected Array list
            String[] expectedLabels={"Basic Info","More about Myself, Partner and Family", "Family","Religious Background","Family","Astro Details","Location, Education & Career","Lifestyle","Partner Preferences","Partner Location","Partner Education & Career","Partner Lifestyle & Appearance"};
            //created actual label list from find element
            List<String> actualLabels=new ArrayList<String>();
            try{
                List<WebElement> lable=driver.findElements(TestUtils.GetPropertiesWeb("AboutMe_BasicInfo"));
                System.out.println(lable.size());
               
               
           
                //for loop -to check every element(e1) from list (lable)
                for(WebElement el:lable){
                    if(!el.getText().equals(""))
                        //adding to arraylist
                        System.out.println(actualLabels.add(el.getText()));
                }
               
                for(int i=0;i<expectedLabels.length;i++){
                    // comparing 2 list
                    if(actualLabels.contains(expectedLabels[i]))
                    {
                        System.out.println(lable.get(i).getText());
                        System.out.println( "matching with expected text" );
                        Reports.addToReport("In Basic Info Section: "+expectedLabels[i]+" Displayed<>ASSERT-PASS<>"+Page,PASS);
                    }
                    else{
                       
                        System.out.println(lable + "not matching with expected text" );
                        Reports.takeSnapshot("Element not found: Basic Info Locator<>ASSERT-FAIL<>"+Page+"<>*",FAIL, driver);
                    }
                }
                   
            }catch(Exception e){
                System.out.println("Lable locator not found");
                Reports.takeSnapshot("Element not found: Basic Info Locator<>ASSERT-FAIL<>"+Page+"<>*",FAIL, driver);
            }
            return this;
        }

    Reading data from excel

    //This function reads data from excel and returns as hash table
        public static Object[][] getData(String sheetName,Xls_Reader xls){
            int rowCount = xls.getRowCount(sheetName)-1;
            int columnCount=xls.getColumnCount(sheetName);
            System.out.println("rowCount="+rowCount);
            int c=0;
            for(int k=2;k<rowCount+2;k++){
                if(!xls.getCellData(sheetName, 0, k).equalsIgnoreCase("Y"))
                    c++;
            }
            int d=0;
            int row=rowCount-c;
            System.out.println(row+"--"+columnCount);
            Object[][] data = new Object[row][1];
            Hashtable<String,String> table=null;
            for(int i=2;i<=rowCount+1;i++){
                if(xls.getCellData(sheetName, 0, i).equalsIgnoreCase("Y")){
                table=new Hashtable<String,String>();
                  for(int j=0;j<columnCount;j++){
                     String key=xls.getCellData(sheetName, j, 1).trim();
                     String val=xls.getCellData(sheetName, j, i).trim();//.split(",")[0];
                     //System.out.println(key+"--"+val);
                     table.put(key, val);
                }
                  //System.out.println(d);
                  data[d][0]=table;
                  d++;
            }
            }
            return data;
        }

    for selendroid switch to webview

     public void switchToWebviewSelendroid() throws IOException, InterruptedException{
              //Thread.sleep(30000L);
              try{
              Set<String> contextNames = driver.getContextHandles();
              for (String contextName : contextNames) {
                  System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
                
              }
              //driver.context("WEBVIEW_com.shaadi.android");
              driver.switchTo().window("WEBVIEW_0");
              }catch(Exception e){
                  e.printStackTrace();
              }
          }