Tuesday, March 14, 2017

Record iPhone or iPad Device Screen and Capture App Log in Mac

Recording device(iPhone/iPad) Screen
 
Sometimes we need to record the mobile device screen for reference of bug verification or capturing an automation run. Recording the device screen is not a difficult step.

There is a default app in Mac by which you can easily record your iPhone or iPad screen. So you don't need to install any other app to do this. The default app which does this is "QuickTime Player"

Steps to record screen:
  • Plug-in the iPhone/iPad device to your Mac
  • Open "QuickTime Player" in your Mac
  • Start a new movie recording(Right click on the icon from the Dock > select "New Movie Recording")
  • On the record menu(arrow right to the red circle) select the device id under the Camera and Microphone section) - as shown in the below image
  • The screen now should be resized to the device screen size
  • Click on the record button(red circle) to start the recording
  • Do any actions that you want to perform in the device to record
  • Click on the stop recording button when you want to stop
  • Save the recording with a name in your local drive
 Note: You can adjust the volume in the volume bar based on the requirement.



Capturing app log in device(iPhone/iPad)

For capturing the application log in the iPhone/iPad device we should have "Xcode" installed in the Mac. Many mac has Xcode installed by default, if not installed then you will have to install it.

Steps to capture log:
  • Plug-in the iPhone/iPad device to your Mac 
  • Open "Xcode" in the system
  • Navigate to "Window" menu and select "devices"
  • In the devices window, select the device name/id from the left panel under the devices
  • In the right panel, click(if the log is not visible) on the upward arrow which shows at the bottom of the right panel of the device window.
  • You will see the running application log in the log panel
  • Clear the log by clicking on the "Clear console" image icon when you don't want the previous log.
  • Click on the "Save Console" image icon to save the log


Capturing screenshots in device(iPhone/iPad)

You can capture the device screenshot in many ways. Below are 2 easy ways to capture screenshot.
  1. Open the device window in Xcode as per the image shown above(follow the previous steps), then click on the "Take Screenshot" button. You will find the screenshot saved in the Desktop.
  2. Press and hold the Sleep/Wake button on the top or side of your device. Immediately press and release the Home button. To find your screenshot, go to the Photos app > Albums and tap Camera Roll.
Note: If you want to take log/screenshot from a simulator, you can select a simulator from the SIMULATORS section and proceed with the required steps.

Monday, September 19, 2016

How to fix INSTALL_FAILED_NO_MATCHING_ABIS error while installing apk in Genymotion

Genymotion is a faster android emulator(Virtual Android Environment) built on x86 and Virtualbox. Its performance is much better than the Google's Android SDK Emulator as it is not an ARM emulator.

However in the latest Genymotion updates, they have removed both the ARM Translation and Google Play Apps. So, when you are trying to install an app which has native libraries but doesn't have a native library for your CUP architecture. For example, if an app is compiled for armv7 and we try to install it on the emulator that uses the Intel architecture instead, it will not work and will give you an error INSTALL_FAILED_NO_MATCHING_ABIS .

To make the app to work in both the CPU architectures, we need to install the ARM Translation.
Steps for installation:
  1. Download the ARM Translation from the link Genymotion-ARM-Translation_v1.1.zip
  2. Open the Genymotion emulator and be in the home screen
  3. Install the downloaded ARM Translation. To installed just you need to drag and drop the zip file in the Genymotion emulator window. Click 'Ok' if it prompts after the 'file transfer in progress' operation
  4. Restart the Genymotion emulator(using adb or close and open)
Now install the application(by using adb or just drag and drop the apk into the emulator window), you shouldn't see any error such as INSTALL_FAILED_NO_MATCHING_ABIS and the application should be installed successfully.

Hope it helps!

Monday, August 01, 2016

Selenium 3(beta) Released!

Selenium 3.0 would be a widely used tool for user-focused automation of mobile and web apps, is expected to be released by Christmas, 2016.

Please watch the video by Simon Stewart, the Selenium project lead and inventor of WebDriver for more details , at  https://m.youtube.com/watch?v=bistojJPR98

Selenium 3 beta released
The beta version of selenium 3 is now released. You can download from
http://www.seleniumhq.org/download/

IMPORTANT CHANGES
* Minimum java version is now 8+
* The original RC APIs are only available via the leg-rc package.
* To run exported IDE tests, ensure that the leg-rc package is on the classpath.
* Support for Firefox is via Mozilla's geckodriver. You may download this from https://github.com/mozilla/geckodriver/releases
* Support for Safari is provided on macOS (Sierra or later) via Apple's own safaridriver.
* Support for Edge is provided by MS: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 
* Official support for IE requires version 9 or above. Earlier versions may work, but are no longer supported as MS has end-of-lifed them.
Other major changes: 
* New html-table runner backed by WebDriver.
* Unused command line arguments are now no longer parsed.

Check below link for the latest updates
https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG

Keep on watching the official website for latest updates at
http://www.seleniumhq.org/

Thank you!

Sunday, April 10, 2016

Regular expressions in test automation

In many of the test scenarios, we need to validate the UI text where the text or partial of it is dynamic. In such cases, we need to use regular expressions to validate the text. Below are few example which can help you.

Example - 1
Suppose you want to validate a pattern 'CHICAGO, IL 60603 (1 mi)'. Where 'CHICAGO, IL' is the location and it follows with a zip and in braces single digit indicating distance in miles. If in this string the location string is as per the preferences or settings that you have made in your application and other part of the string you need to validate, you can write a regular expression as below:
public static boolean validateLocation(String location, 
                             String locationWithZipAndDistance) {
 String locationPattern = location + " [0-9]{5} \\([0-9]{1} mi\\)";
 // e.g. CHICAGO, IL 60603 (1 mi)
 // where value of 'location' is 'CHICAGO, IL'
 Pattern pattern = Pattern.compile(locationPattern, Pattern.CASE_INSENSITIVE);
 Matcher matcher = pattern.matcher(locationWithZipAndDistance);
 return matcher.matches();
}
Usage:
String searchLocation = "CHICAGO, IL 60603 (1 mi)";
String location = "CHICAGO, IL";
System.out.println(validateLocation(searchLocation, location));// output: true
In the above example it will return true if the input string is in either case as it has compiled with CASE_INSENSITIVE pattern.

Example - 2
If you want to validate a phone number text in the UI with a certain format, for example '(866) 825-3227' then you can use below regular expression
public static boolean validatePhone(String phone) {
 String phonePattern = "\\([0-9]{3}\\) [0-9]{3}\\-[0-9]{4}";
 // e.g. (866) 825-3227
 Pattern pattern = Pattern.compile(phonePattern);
 Matcher matcher = pattern.matcher(phone);
 return matcher.matches();
}
Usage:
String ph = "(866) 825-3227";
System.out.println(validatePhone(ph));// output: true
Example-3
Lets assume you are validating some string with days and time, example 'Mon - Fri: 7:00 AM - 6:30 PM', you can use the regular expression in the following way
public static boolean validateOfficehours(String officeHours) {
 String officeHourPattern = "(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat) - (?:Sun|Mon|Tue|Wed|Thu|Fri|Sat): (?:([0-9]{1,2}:[0-9]{2} (?:AM|PM) - [0-9]{1,2}:[0-9]{2} (?:AM|PM))|Closed)";
 // e.g. Mon - Fri: 7:00 AM - 6:30 PM
 // e.g. Sat - Sun: Closed
 Pattern pattern = Pattern.compile(officeHourPattern);
 Matcher matcher = pattern.matcher(officeHours);
 return matcher.matches();
}
Usage:
String officeHoursWeekday = "Mon - Fri: 7:00 AM - 6:30 PM";
String officeHoursWeekend = "Sat - Sun: Closed";
System.out.println(validateOfficehours(officeHoursWeekday));// output: true
System.out.println(validateOfficehours(officeHoursWeekend));// output: true
These are very basic scenarios, using these you can validate maximum of the dynamic texts. Feel free to ask me if you face any different scenarios which need my help.
For more information, please refer here and also you can check the Pattern class for other available functionalities.

Monday, January 18, 2016

Checking if android emulator or device is running

We can check if an android device or an emulator is attached(plugged in) or running before we start using the attached device.

Command line:
We can check the following command to check list of attached devices
adb devices
The above command will provide you the list of attached devices.
Example output,
List of devices attached 
192.168.56.101:5555 device
emulator-5554 device 
Programmatically:
We can do this check programmatically also as below
private static String sdkPath = "/Applications/adt-bundle-mac-x86_64-20140702/sdk/";
private static String adbPath = sdkPath + "platform-tools" + File.separator + "adb";
/**
 * Checks if an emulator or a device is already launched or plugged in
 * 
 * Example: 

 * List of devices attached 

 * 192.168.56.101:5555 device 

 * emulator-5554 device
 * 
 * @return
 */
public static boolean isEmulatorOrDeviceRunning() {

 try {
  String[] commandDevices = new String[] { adbPath, "devices" };
  Process process = new ProcessBuilder(commandDevices).start();

  BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));

  String output = "";
  String line = null;
  while ((line = inputStream.readLine()) != null) {
   System.out.println(line);
   output = output + line;
  }
  if (!output.replace("List of devices attached", "").trim().equals("")) {
   return true;
  }
 } catch (Exception e) {
  e.printStackTrace();
 }
 return false;
}
If the device or emulator is just plugged in or launched, it may not be ready though its running, so wait till it gets ready by the post Waiting for android emulator to be ready