Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

Monday, April 2, 2018

The impact of detecting a bug late in the delivery cycle

The impact of detecting a bug late in the delivery cycle can be best illustrated with this short joke:

Once upon a time, in a jungle there lived a strong and cruel lion. He would hunt and kill animals at random to satisfy his own sadistic pleasure rather than his hunger. All the forest animals lived in perpetual fear of the lion. This cruel and reckless killing went on and on until one day, when the Lion was sleeping all the other animals mustered courage and gathered for a meeting.

“This simply cannot go on!”, the wise old Elephant trumpeted. “We cannot continually live in fear of of the lion. We have to find a solution.”

All the animals in the gathering nodded in assent.

“The Elephant speaks the truth.”, the Giraffe said. “Let’s get our heads together!”

“Let’s set a trap for the Lion in the forest and kill him”, the monkey said.

“Let’s seal off the entrance to his cave. He’ll remain trapped inside and die of hunger and thirst.”, the deer suggested.

The Elephant shook his head. “All that you have suggested has been tried before. The Brute is too strong to be trapped inside. He will simply dig his way out and continue his evil deeds. He is also too cunning and shrewd and can smell any trap.”, he replied sadly.

“What do you suggest then?”, the Wild Buffalo asked.

The Elephant replied, “I have thought about it long and hard. There is only one way. It’s not an easy solution, but it will guarantee that all in the forest will live in peace at least.”

With bated breath the animals waited for the pachyderm to announce his solution.

“I propose that we request the lion to kill one chosen animal each day instead of him killing all of us randomly and indiscriminately. That way only one animal has to die and the rest of us can continue living in peace. We can draw lots and choose the animal from amongst us.”, the Elephant said.

With no better solution in sight, the other animals agreed to his plan. Trembling with fear, they went to the Lion’s cave to put forth their request.

The Lion, fresh after a good sleep was surprised to see the entire forest gather in front of him when he stepped outside.

“Aha!”, he roared. “Today my food has found me, saving me the trouble to search.”

The Elephant mustered courage and addressed the Lion thus, “O Mighty King of Beasts! In the past few years, none of us have been able to escape your cruelty. We live in constant fear of being hunted by you. Our lives and daily routines are in shambles. We cannot continue living like this. Therefore, for the good of the jungle and all those who live in it, we have a proposition for you. Please hear us out. We beg you agree to it.”

The Lion stifled a yawn and said, “Ok, go ahead!”

The Elephant outlined his proposition while all the other animals listened on eagerly.

Finally, when the Elephant was done explaining his solution, the Lion thought for a while.

Then, after what seemed like an eternity for the other animals he said, “I agree!”

The announcement brought loud cheer from the gathered crowd.

The Lion waited for the cheers to subside and then said, “But, I have one condition.”

Silence fell across the crowd, each animal wondering what condition the Lion wanted, worried whether they would be able to fulfill it or not.

“Name it!”, the Elephant said.

The Lion said, “I will tell you a joke. My condition is that all the animals HAVE to laugh. If I see anyone not laughing, the agreement becomes null and void and I will resume my old ways.”

Relieved, all the animals nodded in assent. The Lion started his joke. It was a PJ and probably one of the lousiest jokes they had ever heard. But when he was done, all the animals broke out into hilarious laughter. Even the crocodiles suppressed their tears and were rolling on the ground laughing their head off.

The Lion surveyed the crowd to check if any animal was not laughing, but could find none. But just as he was about to turn away, in the corner he noticed a tortoise peering outside it’s shell. The tortoise looked around grim and serious, probably wondering what the commotion was all about.    

“Aha! I see one animal not laughing to my joke.”, he said pointing to the tortoise. “The agreement is now null and void. I shall resume my old ways again”, the Lion roared.

The animals angrily glared at the tortoise which innocently went inside its’ shell, totally oblivious to the situation.

Once again, the Lion resumed it’s old cruel ways. But the next day, the animals gathered outside the Lion’s cave again and one more put forth their proposition. The Lion agreed but with the same condition as before. This second joke was even more stale and lousy than the first one, but all the animals put up a brave front and laughed their head off. All, except the tortoise which once again grimly stared outside his shell, a dead serious expression on his face. Once again, the Lion noticed the Tortoise and pointed it out with devilish glee. All the animals looked daggers at the amphibian which, oblivious to the hostility directed at it slunk back inside its’ shell.

And yet again, the lion resumed it’s cruel ways. But after a few days, the animals gathered again outside the Lions’ den to make the same request. This time they did not tell the tortoise as they feared it would spoil the show again. But the tortoise got wind of the plan and followed them at a distance.

But this time, the Lion had a different condition.

“I will tell you a story. All of you will have to CRY at this one. This is your last and final chance. If you screw up I will get back to my old ways and this time, no one will stop me!”, the Lion roared.

Terrified, the animals waited till the Lion completed his story. When he was done, they started bawling shamelessly. The Hyena came out of his comfort zone and really cried his heart out. Loud sounds of tears and crying could be heard from all sides. The Lion did a careful survey to check for any defaulters. And to his surprise, this time he saw the tortoise rolling over in his shell, LAUGHING away to glory.

Enraged, he roared, “THIS IS AN INSULT! THE DEAL’S OFF!” pointing towards the amphibian.

Dismayed, the animals looked at the direction the Lion was motioning and noticed the tortoise laughing.

Once again, oblivious to the situation around him, the tortoise innocently said between laughs, “That first PJ was hilarious!”  

--------------------------------------------------------

Here are some lessons from this joke:


Hope you enjoyed the joke and more so, the meaning I tried to convey through it. Detecting a major bug very late in the delivery cycle can cost a lot to fix in terms of effort, quality and not to mention frayed tempers and overall project health. So as a good tester, it's of paramount importance to prioritize your tests and make sure the critical scenarios are covered first to reduce risks.

Happy testing !!

Cheers,

Srinivas Addanki







 

Thursday, September 22, 2016

Murphy's Laws of Software testing

Taken from my facebook wall. Here goes:

1) Bugs can easily be created. They cannot however, be easily destroyed. But they can easily get transferred from one platform to another.
2) There is no such thing as a bug free application. But yes, bugs do come free with every application. :)
3) Bugs do not get reproduced when you demo them to the developer / project manager.
4) But will magically reappear from nowhere when you demo your product to the client / customer.
5) Your most bug-free product version will reside in your developer’s local machine / session. Bugs never happen there.
6) The more the number of developers working on the product, the more bugs there will be to find.
7) Bugs which have been deemed fixed and closed always reoccur in Production.
8) No matter how extensive your test coverage is, you will always miss / overlook one aspect of the product.
9) And that’s where the bug will usually occur in production.
10) No matter how many critical bugs you find, you will be pilloried for the one bug you failed to detect.
11) The PM and delivery manager will always consider the testing team as dead weight.
12) The bug which takes the maximum amount of time to reproduce will always take the least amount of time to fix.
13) The bug which causes the maximum amount of damage always requires the smallest of fixes.
14) Customers / End users usually find more bugs than your testers’ do.
15) Bugs will never be apparent if you keep looking for them, but when you are not, they will pop up from every nook and corner of the application and will hit you in the face.
16) Automation might get things done quicker, but the amount of time it takes to script the tests and run them will make you think of running the tests manually.
17) The most critical and time consuming bug for the developers to fix will always occur at the fag end of the testing cycle or when the product is ready to ship.
18) You will spend a huge amount of time and energy in detecting a bug only to find that it now not reproduced.
19) Even if you do reproduce the goddamn bug and file it, it inadvertently turns up not to be in scope.
20) Even if it is in scope, someone else would have already filed it a long time back.
21) The product / feature for which you have detected the maximum number of bugs will most certainly be de-scoped.
Developers’ ultimate justification for bugs:
“But it does not happen on my local machine!!” :)
"This issue is not in scope."

Murphy’s Ultimate Law of all products:
“It just won’t work!”

Thursday, December 10, 2015

Installation and setup of Appium tool for Android via JAVA

Hi folks. Hope you're all in good spirits. For those of you into automation, desktop or mobile: Open source tools rule. And they rule because they are, well ... Open source. Open source tools are freely available for use by all. And what's more, if you are well acquainted with these tools, you'll find your career graph shoot up exponentially. Unfortunately, since they are open source there's not much of documentation and support available for them online. Most of these tools are updated and documented by programmers passionate about these tools and software in general. Hats off to them.

There are numerous open source automation frameworks available these days for automating Mobile and Web apps. Appium is one such popular tool. It can be used to automate native, hybrid and web based apps and pages on iOS, Android and FireFox OS operating systems.

In this blog, I will outline the steps required to install and setup Appium for automating Android application using JAVA on your Windows machine. This blog will cover the following topics:

  1. A brief introduction to Appium and it's features
  2. Pros and Cons of using Appium
  3. Tools required to run Appium
  4. Installation and setup of Appium (for running tests via JAVA)

Why Appium?


Pros

Appium has the following advantages:

  1. Appium is open source and free. All supporting tools required for setting up the Appium Test Framework are open source and can be downloaded from the net. There are no licensing and fees involved.
  2. Appium can automate a wide variety of apps supported on major mobile Operating Systems such as Android, iOS and FireFox OS.
  3. Appium supports the Selenium Web Driver framework, so users can script their tests in various Web Driver Compatible languages such as JAVA, Python etc and also use Selenium WebDriver Libraries.
  4. Appium scripts are cross-platform compatible. A Script created for Android can also be used for iOS as well(with a few tweaks of course).
  5. User does not require the source code for running tests.
  6. User does not need to recompile the app again for running Appium tests. This means that your app is tested as is in real world conditions.
  7. Appium is supported by proprietary cloud based test frameworks such as Saucelabs which can run your tests on Simulators close to actual device requirements
  8. There is no need to Jailbreak or root the device for running Appium Scripts
  9. Appium provides a wide range of versatile functionalities for running tests.  

 Cons:


Appium has the following disadvantages:

  1. Appium setup is a bit complicated and time-consuming, especially for first time learners.
  2. Appium cannot support OS below 4.2
  3. Appium does not have a record and playback tool for Windows
  4. Appium is not very stable at high loads.

Appium Architecture


Appium is actually a server written in Node JS. Clients initiate a session with the Appium server by ending a POST request with instructions (containing the code for tests to run). Settings required to run the test are sent to the server through the 'Desired Capabilities' object. After receiving the request, Appium sets up a session on the server with a unique session ID. User can now send multiple test requests for execution after the server is setup. For Android, Appium uses the UIAutomator framework and sends a HTTP response to the client.


Installing and setting up Appium on your windows machine for Android Tests  


Installation and proper setup of the Appium test framework is the most crucial and complicated step for running your Appium Tests. Without proper setup, you will not be able to run your Appium tests. What makes the setup process complicated is the dependency the Appium tool has on other third party and open source applications and software. Apart from the actual server application (Appium.exe) itself, you will require installation of various other third party tools for proper execution. The entire installation and setup process is mentioned below:

 

Tools required for setting up Appium


 

Appium.exe

 

This is the windows Appium server application. It can be downloaded via the Official Appium WebSite.

For downloading the latest Appium Server app, follow the instructions below:

  • Open the Appium Website.
  • Click on the 'Download Appium' link seen on the website. This will automatically start the download of the latest version of the Appium application

 

Node JS


The latest version of Appium has Node JS included which automatically installs along with the Appium server installation. If you are using an older version of Appium then you need to install Node JS on your machine. It can be downloaded and installed from the official Node JS website. 

 

JAVA - JDK & JRE


The latest version of the JAVA SE Development Kit (JDK) needs to be downloaded from the Oracle Website.




 

Eclipse


Download the latest Eclipse tool for scripting and executing your JAVA code. Download from the Eclipse Website.


 

Setting up Environment and System variables for JAVA


After installing JAVA and eclipse, you need to set the proper path for JAVA via the Environment variables window. Click on the Windows Start button. In the Start menu right click on 'My Computer' and select 'Properties'.



This will open the 'System Properties' page. Click on the 'Advanced System Settings' link seen in the left hand side of the page. This will open the 'System Properties' window. Click on the Environment Variables button at the bottom.


Here you will see two types of variables, user variables and system variables. User variables are settings for the specific user only. System variables are variables for all users accessing the machine. Choose any type of variable as per your needs.


Create new System variable 'JAVA_HOME' and set value to your JDK installation directory.

In the PATH system variable, add the following parameter:

<Path to your JDK folder>\bin

Eg: C:\Program Files\ Java\ jdk1.8.0_40\bin

 

Android SDK


Go to the relevant Android web site and download the latest Android Software Development Kit for your machine. SDK zip gets downloaded. Extract the same on your machine and make a note of the path.

 

Setting up Environment and System variables for ANDROID


Go to My Computer >  Properties > Advanced System Settings > Environment Variables

Create a new system variable ANDROID_HOME and set the value to the path where the SDK is extracted on your machine.

ANDROID_HOME: <path to your SDK folder>\sdk

Ex: ANDROID_HOME: D:\Work\android_sdks

The edit the 'PATH' system variable and add the following values to the same:


  • %ANDROID_HOME%/tools
  • %ANDROID_HOME%/platform-tools

 

 

Enable developer 'Options' on your device or Emulator


In case developer options are not enabled on your emulator or android device, enable the same by going to Device Settings. Tap on the 'About Phone' link 6 times. Developer options will appear. If your phone is connected to PC, your device will be prompted to accept an RSA key for linking between device and PC. Accept the same. This will ensure that your device  /emulator is properly linked to your PC / Laptop.

Download and Install PdaNET software (optional)

Go to the PDA website. Download and install the latest version of the Software PdaNet+. This will install the latest drivers for your phone. This will ensure that your phone is detected in the Android Device Monitor. Use this option if your laptop does not detect and install the mobile device USB drivers automatically.



 

Microsoft .NET framework version 4.5 or above


MS.net is essential for Appium to function. Go to the .NET download page and download version 4.5 or later.


Selenium WebDriver Files


Go to the Selenium Website, download and extract the following files to any safe location on your PC / Laptop:

a) Selenium Standalone Server file (Jar file)
b) Selenium Client and WebDriver Binding files for JAVA




 

 

Appium language bindings for JAVA


Last but not the least, we have to download the Appium JAVA binding file for JAVA. It's a JAR file and can be found at the following location:





Now you have all the files you require for setup. Now let's look into the installation of the Appium server for running our automation Scripts.



Setting up your Appium Test project in Eclipse



  1. Download the APK to be tested to any safe location on your PC / Laptop. For this example, we are going to automate the simple Android calculator for this sample project test.
  2. Extract and download the Selenium Standalone and WebDriver files to any location on your PC. Note the location.
  3. Open Eclipse. Start a new JAVA project. Click on New > JAVA Project



        4. Create a new JAVA project for ex: "NewAppiumTest"

        5. Create a new package ex: 'AppiumTest'

        6. Create a new class file ex: 'AppiumTest' (or any other name as per your choice).

        7. Right click on project folder and Select Build path > Configure Build path.

        8. In the JAVA build path window, switch to 'Libraries' tab.

        9. Click on the 'Add External JAR's' button and add the following JAR files:

             a) The Latest Appium JAVA binding file

                 




























              b) The latest Selenium JAVA Web Driver JAR file:





























             c) All the jar files in the /libs folder





























              d) The selenium server standalone JAR file





























      10. Connect your device to your PC/Laptop via USB. Ensure that USB debugging is ON.



Executing your First Appium Script

 

Congratulations. The Appium setup part is done. You are now ready to execute your first Appium Script. For this demo we are going to use the simple Android Calculator application. Place the file at any desired location on your PC / Laptop and remember it (Ex: D:\Radio\AndroidCalculator-V1_0.apk)

Import the Selenium WebDriver and Appium Driver libraries to your Appium Script:

 

import io.appium.java_client.AppiumDriver;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

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

import org.openqa.selenium.remote.RemoteWebDriver;
                    
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;


Importing these libraries will call Web Driver interfaces and classes for running tests.

Note: Not all the libraries imported will be used in your test script. But it is better you import all of them to avoid any run-time compilation errors.

Create the methods for scripting your tests:



public static void main(String[] args) throws Exception {
          // TODO Auto-generated method stub
          // creating a class object
       AppiumTest testcases = new AppiumTest();
         // call launch app method
         testcases.launchCalc();
         // call add name method
         testcases.addName();

}          



Setup the Android APK file path:


public void launchCalc() throws InterruptedException, MalformedURLException
         {
         
File app=new File("D:\\Radio\\AndroidCalculator-V1_0.apk");


Initialize the test method. Remember the path to the Android APK you want to test and setup the path accordingly.



Set the Desired Capabilities:


Desired capabilities are a set of values sent to the Appium server which define the parameters for the test to be executed. They are setup in the following manner:


DesiredCapabilities capabilities = new DesiredCapabilities();

//Name of mobile web browser to automate. Should be an empty string if automating an app instead. 
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

//which mobile OS to use: Android, iOS or FirefoxOS
capabilities.setCapability("platformName", "Android");

//Mobile OS version – in this case 4.4.2 since my device is running Android 4.4.2
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
                

       

           //device name – since this is an actual device name is found using ADB devices command in CMD
         capabilities.setCapability("deviceName", "92268ee10561a040");


         //the absolute local path to the APK

         capabilities.setCapability("app", app.getAbsolutePath());



         //Java package of the tested Android app
         capabilities.setCapability("appPackage", "com.calculator");

         // activity name for the Android activity you want to run from your             . This need to be preceded by a . (example: .MainActivity)
                                                          capabilities.setCapability("appActivity", ".Main");
 
 

Note: 

  • Device name can be detected by entering the command 'adb devices' in your command prompt window.
  • Your Android App package name and Main Activity name can be detected by using the following command:
           aapt list -a "path to apk"> file.txt
          Alternatively, loading the APK in Android settings of the Appium tool gives the package and 
          the main activity info also. 

Starting your test


Initiate your test by adding the following:


// constructor to initialize driver object

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
 
This is the default port number from which the Appium Server will be initialized.

Detecting Elements on your Android App


Elements can be detected by using the UI Automator application. This application is found in the 'tools' sub folder of your Android SDK folder. To detect the element, open UI Automator and take a screenshot of the page on which the script is to be run.


The right hand side of the UI Automator application shows all the elements of the page grouped by classes. Click on the desired element in the screenshot. The bottom right hand side window will populate with all the details of the selected element. For example, click on the text window under the text "Enter First Number". The element gets highlighted by a red rectangular colour. You will see the element details populate on the bottom right side table. Since we are using Selenium Web Driver libraries and classes, we can use the 'findelement' method to detect and select elements using various parameters such as 'Class', 'Name' or 'Id'.

To detect and select the element, first create a WebElement object and assign the relevant method to it:

For example:



//locating the First text box
WebElement FirstNo = driver.findElementById("EditText01");

Here, EditText01 is the element id if the first text box. You can click / activate the text box and enter a value in it by using the following commands:

//Clicking the First Text Box and entering the value

FirstNo.click();
FirstNo.sendKeys("56");
 
This will activate the First text box and enter the numeric value '56' in it.

You can create a similar script for locating the second text box and entering a value it in:

          //locating the second text box

WebElement SecondNo = driver.findElementById("EditText02");
 



//Clicking the Second text box and entering the value
           SecondNo.click();
           SecondNo.sendKeys("65");

Similarly, create an object for the multiply button, select it and click on it by using the following code:


//Select and click the multiply button

WebElement Multiply = driver.findElementByName("Multiply");
Multiply.click(); 

This should click the 'Multiply' button and display the result of the product of '56' and '65'. After your test is done, use the following command below to exit the script cleanly and end the test.


driver.quit();
Optiona: You can import TestNG assertions and add an assert to make sure that the result is as per specification.
 
Your complete Appium Script should look something like this:


package <Your Package name>;

import io.appium.java_client.AppiumDriver;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.junit.*;
import org.openqa.selenium.remote.RemoteWebDriver;

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

import org.testng.annotations.Test;




public class AppiumTest {
      
       AndroidDriver driver;
      
       public static void main(String[] args) throws Exception {
              // TODO Auto-generated method stub
              // creating a class object
           AppiumTest testcases = new AppiumTest();
             // call launch app method
             testcases.launchCalc();
             //Start GlobalMenu
             //testcases.launchGMenu();
             // call add name method
             testcases.addName();


}

       public void launchCalc() throws InterruptedException, MalformedURLException
         {
         
          File app=new File("D:\\Radio\\AndroidCalculator-V1_0.apk");
            
          
          
           DesiredCapabilities capabilities = new DesiredCapabilities();

         //Name of mobile web browser to automate. Should be an empty string if automating an app instead.
         capabilities.setCapability(CapabilityType.BROWSER_NAME, "");

         //which mobile OS to use: Android, iOS or FirefoxOS
         capabilities.setCapability("platformName", "Android");

         //Mobile OS version – in this case 4.4 since my device is running Android 4.4.2
         capabilities.setCapability(CapabilityType.VERSION, "4.4.2");

         //device name – since this is an actual device name is found using ADB
         capabilities.setCapability("deviceName", "92268ee10561a040");

         //the absolute local path to the APK
         capabilities.setCapability("app", app.getAbsolutePath());

         //Java package of the tested Android app
         capabilities.setCapability("appPackage", "com.calculator");

         // activity name for the Android activity you want to run from your package. This need to be preceded by a . (example: .MainActivity)
         capabilities.setCapability("appActivity", ".Main");

         // constructor to initialize driver object
         driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
           Thread.sleep(4000);
           System.out.println("App Launched");
           //locating the First text box
           WebElement FirstNo = driver.findElementById("EditText01");
           //Clicking the First Text Box and entering the value
           FirstNo.click();
           FirstNo.sendKeys("56");
           Thread.sleep(2000);
           //locating the second text box
           WebElement SecondNo = driver.findElementById("EditText02");
           //Clicking the Second text box and entering the value
           SecondNo.click();
           SecondNo.sendKeys("65");
         //Select and click the multiply button
           WebElement Multiply = driver.findElementByName("Multiply");
           Multiply.click();
           Thread.sleep(10000);
           driver.quit();
          
         }
      
       public void addName() throws InterruptedException {
            System.out.println("Test success");
                // write all your tests here
          
           
          }

}


Since the actual test runs very fast, I have added a few thread.sleep methods to pause the test in between, so that you can get a better idea of how the test runs and to give the app some breathing space (Phew!)
 

Starting the Appium Server


This step is crucial to running your tests. Without this, your tests will not execute. Start the Appium.exe application on windows. Click on the 'Android' button to set the Android settings.


Click on the 'Choose' button, browse and select the APK to be tested. App package and Main Activity details will be displayed automatically. Enter device name as derived from the command 'adb devices' in CMD.

Click on the general settings icon and check the server number and port number from which the Appium server will be launched.

Now click on the 'Play' button on the top right corner of the Appium window. This will start the Appium server. The Appium server will look like below:


Now run the JAVA test you have in Eclipse and watch the result on your device.

Here we have reached the end of this blog. Hopefully, you have learned something useful from this blog and hope this helps you install and run Appium Scripts smoothly.

There is more to this. In my next blog, I will take up other commands and reporting via Test NG etc. Stay tuned !!

Thank you for taking the trouble to read this blog. Comment and criticism are always welcome.

Enjoy !!