Tuesday, 19 January 2016

Java Appium - Performing Drag and Drop

Download 'Drag and Drop' demo app from play store.
 



Click 'INSTALL' button.


Click 'ACCEPT' button.




Launch 'ApkInfo' app to identify 'appPackage' and  'appActivity' of  'Drag-Sort Demos' app.

To know more about 'Apk Info' app watch the below video
http://automation-home.blogspot.in/2015/05/appium-java-executing-appium-webdriver-script.html

 
  
If you are new to Appium watch the video demo's present at
 

Sample Program:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

public class DragAndDropTest {
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        AppiumDriver driver;

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "392c8ab5");
        capabilities.setCapability("platformVersion", "4.4.4");
      
//below statement is commented.
//I have already installed 'Drag-Sort Demos' app in my android device,
//so iam not installing the 'Drag-Sort Demos' app through appium for performing automation        //capabilities.setCapability("app",System.getProperty("user.dir")+"<<PATH of APK file>>");
      
        capabilities.setCapability("appPackage", "com.mobeta.android.demodslv");
        capabilities.setCapability("appActivity", ".Launcher");

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
         driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
      

        driver.findElementByName("Basic usage playground").click();
      
        List<WebElement> elements = driver.findElements(By.id("com.mobeta.android.demodslv:id/drag_handle"));
        WebElement srcPos = elements.get(4);
        WebElement dstPos = elements.get(0);

        TouchAction ta = new TouchAction(driver);
        ta.longPress(srcPos).moveTo(dstPos).release();
        ta.perform();
      
            Thread.sleep(4000);
        driver.quit();
    }
}

Friday, 15 January 2016

Javascript Part-2


Prerequisite:
http://automation-home.blogspot.com/2016/01/javascript-part-1.html

Agenda
  • document.URL
  • document.lastModified
  • document.readyState
  • document.getElementsByTagName(….)
  •   |- textContent
  •   |- innerHTML
  • document.getElementsByName(….)
  •   |- value
  •   |- click
  • document.getElementsByClassName(….)
  •   |- value
  •   |- click
  • document.getElementById(….)
  •   |- value
  •   |- click
  • document.getElementsByTagName(….)
  •   |- mouseover

Wednesday, 13 January 2016

Javascript Part-1


Agenda
  •     Writing the JavaScript in HTML file.
  •     Writing JavaScript functions outside the HTML file and using in HTML.
  •     Executing Javascript statements in browser console.
  •     window.alert(....)
  •     window.open(….)
  •     window.loc
  •     window.location
  •       |- window.location.href
  •       |- window.location.origin
  •     document.fullScreen
  •     document.write(...)
  •     document.title
  •     window.document.title

Friday, 1 January 2016

Android mobile automation - USB Troubleshooting

Issue 1: If command 'adb devices' is not detecting your android device.
Solution 1: 
    Check 'Developer options' is enabled in settings
    USB debugging is enabled.
    Mobile device drivers are installed in computer.


    Check 
     - 'Developer options' is enabled in settings and
     - USB debugging is enabled.
  
Now run the command 'adb devices', if still device details are not displayed.
Install mobile device drivers on your computer and check again by running command 'adb devices'.

Solution 2:
  Try with uncheck and check 'USB debugging'. 


Issue 2: Even after enabling 'developer options', 'usb debugging' and 'phone drivers are installed'. If the issue is not resolved, try with 'updating driver software' in 'device manager'.
Solution:
  Search for 'device manager'.

perform 'Update Driver Software'.



Issue 3: If command 'adb devices' is not working or not showing the device information, then try with below adb commands in command prompt.
Solution:
   adb kill-server
   adb start-server
   adb devices


Issue 4: Check USB cable.
Solution 1:
  Disconnect and re-connect usb cable to Computer and Phone.  

Solution 2:  
   If your device is not detected, unplug the usb cable and connect it to different usb socket on your computer. 

Solution 3:
Make sure both ends of USB cable are properly connected to computer and mobile device.

Solution 4:
Some time due to loose USB connectivity, usb may not be recognized.
Push usb cable up and down slightly(be careful while doing this, it may bent completely).
Note: This approach is not recommended.


Issue 5: Phone isn't detected via USB, but still charges.
Solution 1:
    Go to dial pad & type *#0808#
    It displays USB settings
    Select MTP+ADB option
    Press OK button
    Connect to USB cable to PC
    It shows Connected as a media device.



Solution 2:
I got this problem(i.e. phone is charging, but usb is not recognized), tried with all possible solution but usb is not recognized in 'Windows 7 Professional' Operating System.

Below popup appears when usb is connected to computer.

Based on the workaround provided in youtube, changed the USB cable(i.e. replace with new USB cable) and the issue got resolved, this is mainly due to the cheap USB cables.
  
Issue 6: If adb commands not working i.e. 'adb kill-server', 'adb start-server' and 'adb devices'.
Solution:


check if old adb server is running
Run the command 'tasklist | findstr /i adb' in command prompt.

If adb server is still running, then kill the process by running the command "taskkill /f /im adb.exe".

Check if anything is listening on port 5037, by running command 'netstat -ano | findstr :5037'

If process it not killed, then kill the process in task manager.
Restart computer and mobile device.

Referencehttps://code.google.com/p/android/issues/detail?id=184713

Issue 7: If multiple usb drivers are installed.
Solution:
If different USB devices are plugged-in (or) many users plug in different usb devices like pen drives, cameras, etc. then multiple usb drivers are installed on your computer, your computer doesn't know 'what' it is (i.e.android phone). 

Uninstall all inactive drivers.

Add the 'System Variable' with name 'devmgr_show_nonpresent_devices' and value '1'.


Search for 'Device Manager' and click on 'Device Manager'. 

Click 'View' >> 'Show hidden devices'.

Expand 'Universal Serial Bus controllers'.
Note: In above screenshot some of the driver software's are already uninstalled before taking the screenshot. 

Uninstall driver software's for inactive devices(drivers which are faded).

Search for file 'INFCACHE.1' and delete the file.
'INFCACHE.1' file is found at location 'C:\Windows\System32\DriverStore'.

Add 'Administrators' in Security tab to delete the file 'INFCACHE.1'.



Check 'Administrators' is having full permissions.

Now delete the file 'INFCACHE.1'. 

Restart computer and mobile device. Connect usb, file 'INFCACHE.1' is re-created once the usb is recognized. 

Reference:


Other Reference: