Saturday, February 13, 2016

Random Testing Tips

I am writing this post based on my experience that span over around seven years and I feel that things that have helped me and my other fellow team members in doing testing effectively and swiftly are worth sharing. The list will continue to evolve over time, so stay tune. I would be glad to know your feedback and tips on typical day of testing. ☺

Tip 1: Removing Distraction.

During testing there are so many distractions you come across daily but this distraction is something different. When you are verifying or executing some scenarios you see some unexpected and unusual state or things within the application under test that is not part of your current expectation so as a tester you should NOT leave your current execution and start probing the new problem you see but rather you should note down  such unusual things and continue your current tasks. When you finished then definitely as a good tester you should report and trace each and every problem within the application.
  
Tip 2: Dealing Credentials Scarcity.

There are times when you're testing with applications that require multiple unique email addresses to register for different roles and views. To cater this need there is a very handy technique you can use to create multiple users/emails. For example, if you have an email address john.doe@gmail.com and you need to create 3 different roles/users scenarios in an application say Customer, Sales, Admin or Sysadmin so you can create all user using existing email like john.doe+customer@gamil.com, john.doe+sales@gamil.com and
john.doe+sysadmin@gamil.com and you can have personalize view of each respective users based on your application and needs. All related emails (if application under test generate some) will be delivered to only john.doe@gamil.com and you can SAVE crucial time wasted in creating different valid (email receivable) email addresses.

Tip 3: Winning Developer Trust.

Sometimes as a tester we write a very robust defect report and try to put ever related stuff and condition but developer actually interested in one direct clue and source of a problem. That very clue is very easy to find. Modern browser are coming  with robust built-in debugging tool like Developer Panel within the browser. As a tester what you can do is you can keep open (Windows = F12 or CTRL+SHIFT+I; Mac = CMD+OPT+I) that panel to see which request is failing, giving error or simply not even actually triggered by clicking the specific request url and then clicking response tab to see its details. That way you will be able to add that clue in defect report that developer can directly jump into fixing quickly and definitely you will be treated as reliable tester for her code.

Tip 4: Testing with large size file

Sometimes you might need large files to test the application and creating large files is always a challenge. But there are many solution and the one am sharing is very handy, and to that we can use the concatenation of single file. Use the following command on your Unix/Linux shell:
Prerequisite: You should have at least one file with some data in it either compressed or uncompressed.
cat   < existing-file > >>  < new-file >

Repeat the above line as many time as you want to generate size of the file you needed for testing. Alternatively you can create shell script to do this automatically an repeatedly for you as follows.
../bin/generate_large_file.sh
for i in {0..100}; do cat < existing-file > >>  < new-file > ; done 
Save the above script and execute as ./generate_large_file.sh it will loop 100 times and append the existing files into new file to create large size file with same repeating contents in the same directory where original file and shell file reside.
  

Friday, January 15, 2016

Different characters in software development... -A short blog post

There are many people with different roles and responsibilities e.g. software developers, testers, marketing, sales and business development are involved in developing product with common set of goals like making a world a better place; and yet many people within the same organization do not value other peoples' work and take it for granted.

It happens quite often and people especially testers are complaining about the fact the are treated in isolated way. For example, they are treated as the expense on the company's balance sheet rather than assets and their work is taken many times for granted and many times their efforts are ignored. If tester finds a defect put enough effort in analyzing the issue but not able to get specific steps to reproduce the issue developers do not take it seriously and it keeps in the backlog for days, weeks and even months. But as soon the same or similar issues are reported from within the field or by some business related people it  becomes a nightmare for the entire engineering team and they put every bit of effort in reproducing and fixing that problem at any cost.

Above and such similar problems are real cause of the demotivation of testers within the industry. 

Do you have any similar instances to share ?

Friday, January 1, 2016

Leveraging python scripts

In the recent past I happened to have assigned a task of Uploading 200K files in total to some cloud app for testing purpose. The challenge was to create that many files, but, thanks to Python robustness that helped me saving myself from laborious and tedious work of creating folders and files within those folders.

Following is the script for that purpose.


========================================================== 
#This script creates total of  200000 Files in 2000 folders 
#i.e each folder e.g MZ_STRESS_1 contains 100 text files
import os

file_list = os.listdir(r"F:\\python_projeects\\Folder_Library")
print(file_list)
current_path = os.getcwd()
print("Current working directory : "+current_path)
os.chdir(r"F:\\python_projeects\\Folder_Library")


for x in range(1,2001):
    os.mkdir(r"MZ_STRESS_"+str(x))
        for y in range(1,101):
            fo = open("F:\\python_projeects\\Folder_Library\MZ_STRESS_"+str(x)+"\\File_"+str(y)+".txt", "wb")
            fo.write(u''+u'\n')
            fo.close()

print("Job finished!!!")

==========================================================
   
Share your snippets you've ever prepared for doing such and similar small tasks using any language.


Happy testing! :-)





       
       

Wednesday, December 30, 2015

Sending concurrent requests

Many times the testing demands for testing for concurrency which is a very common case in today's scenario of website application development. The challenge for the testers is mimic the actual concurrent scenario manually, which is nearly impossible by manual effort. However, this could be done by using many testing tools or by use of some robust scripting language like Python (as used in the following snippet) to generate concurrent request for the particular URL/API/UI endpoint using the basic authentication.


Pre-requisite

Install python

Then install grequests by the following command

$ pip install grequests


#/home/python/bin/

import grequests
import itertools
from requests.auth import HTTPBasicAuth


username = 'username or email' #Updated this field with required username
password = 'password' #Updated this field with required password


#Updated the following URL with the one needs to be concurrently tested.
reqs = 'URL/API/UI endpoint where concurrent requests need to be sent'

# below 20 represent the count of concurrent requests and 'grequests' support around 2K concurrent request
urls = itertools.repeat(reqs, 20)

def sendConcurrentRequest():
     rs = [grequests.get(u, auth=(username, password)) for u in urls]
     print len(rs)
     

     xs = grequests.map(rs)
     print xs


if __name__ == "__main__":
sendConcurrentRequest()

Wednesday, May 7, 2014

When to Automate Software - Part 1

Problem

There are times in the application development when new feature and/or functionality keep adding into the existing software and there are functionality that are unchanged but have its own value in the application, sometimes such functionality becomes a bit boring for the testers to test over and over again after each feature functionality integration and that increases the chances of defect slippage, testers started to make assumptions and based on those assumption she might skip some key tests in that functionality that results in defect in later stages.

Solution

The solution for the above problems in which similar tests need to be executed again and again it is better we should automate those tests that are repeatable. Each time the test is going to be executed its value increases and confidence of each run will remain unshakable as it was in the first run.

See the following example, in which the form Reset functionality needs to be tested over and over again since it is one of the basic feature the EfroTech site provides.

Scenario
  • Launch application
  • Click on Jobs
  • Fill up the form
  • Click Reset button

Expected: All fields on the form are reset to default except Salary fields.

Test Case Class

 package com;  

 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.support.ui.Select;  

 public class EfroTechCareers {  
      private WebDriver driver;  
      public EfroTechCareers(WebDriver driver)  
      {  
           this.driver = driver;  
           if(!"Jobs and Career at Efrotech | Efrotech Services".equals(driver.getTitle()))  
           {  
                throw new IllegalStateException("This is not the Careers Page");  
           }  
      }  
      By applyingFor = By.id("ddlJobs");  
      By candidateName = By.id("txtName");  
      By candidateFatherName = By.id("txtFName");  
      By candidateGender = By.id("ddlGender");  
      By candidateAddress = By.id("txtAddress");  
      By candidateCity = By.id("ddlResumeCity");  
      By candidateEmail = By.id("txtEmail");  
      By candidateHomePhone = By.id("txtPhoneHome");  
      By candidateOfficePhone = By.id("txtPhoneOff");  
      By candidateCellPhone = By.id("txtPhoneMob");  
      By candidateCNIC = By.id("txtCNIC");  
      By candidateExperience = By.id("ddlExperience");  
      By candidateCurrentSalary = By.id("txtCurrentSalary");  
      By candidateExpectedSalary = By.id("txtExpectedSalary");  
      By btnFormReset = By.id("btnReset");  
      public void formFillCareers()   
      {  
           driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[height='520']")));  
           new Select(driver.findElement(applyingFor)).selectByVisibleText("QA Engineer");  
           driver.findElement(candidateName).sendKeys("Candidate Name");  
           driver.findElement(candidateFatherName).sendKeys("Cand. Father's Name");  
           new Select(driver.findElement(candidateGender)).selectByVisibleText("Male");  
           driver.findElement(candidateAddress).sendKeys("XYZ Lane 123 Road");  
           new Select(driver.findElement(candidateCity)).selectByVisibleText("Karachi");  
           driver.findElement(candidateEmail).sendKeys("name@domainname.com");  
           driver.findElement(candidateHomePhone).sendKeys("12345678");  
           driver.findElement(candidateOfficePhone).sendKeys("87654321");  
           driver.findElement(candidateCellPhone).sendKeys("03331234567");  
           driver.findElement(candidateCNIC).sendKeys("12345-6789458-9");  
           new Select(driver.findElement(candidateExperience)).selectByVisibleText("5 Years");  
           driver.findElement(candidateCurrentSalary).sendKeys("123456");  
           driver.findElement(candidateExpectedSalary).sendKeys("654123");  
           driver.findElement(btnFormReset).click();  
      }  
      public boolean verifyFormReset()  
      {  
           if (  
                     ("-Select-".equals(new Select(driver.findElement(applyingFor)).getFirstSelectedOption().getText()) &&    
                     "".equals(driver.findElement(candidateName).getText()) &&  
                     "".equals(driver.findElement(candidateFatherName).getText()) &&   
                     "-Select-".equals(new Select(driver.findElement(candidateGender)).getFirstSelectedOption().getText()) &&   
                     "".equals(driver.findElement(candidateAddress).getText()) &&  
                     "-Select-".equals(new Select(driver.findElement(candidateCity)).getFirstSelectedOption().getText()) &&   
                     "".equals(driver.findElement(candidateEmail).getText()) &&   
                     "".equals(driver.findElement(candidateHomePhone).getText()) &&   
                     "".equals(driver.findElement(candidateOfficePhone).getText()) &&   
                     "".equals(driver.findElement(candidateCellPhone).getText()) &&  
                     "".equals(driver.findElement(candidateCNIC).getText()) &&  
                     "-Select-".equals(new Select(driver.findElement(candidateExperience)).getFirstSelectedOption().getText()) &&  
                     "012345".equals(driver.findElement(candidateCurrentSalary).getAttribute("value")) &&  
                     "065412".equals(driver.findElement(candidateExpectedSalary).getAttribute("value"))   
                     )  
            )  
                          return true;  
                                         else   
                                              return false;  
      }  

 } 


 

Main Class Calling the Test Case Class

 package com;  

 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.openqa.selenium.support.PageFactory;  

 public class EfroTechMain {  
      /**  
       * @param args  
       *   
       */  
      public static WebDriver driver;  
      public static String baseUrl;  
      public static void main(String[] args) {  
           // TODO Auto-generated method stub  
           baseUrl = "http://www.efrotech.com";  
           driver = new FirefoxDriver();  
           driver.manage().window().maximize();  
           driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
           driver.get(baseUrl +"/careers");  
           EfroTechCareers eTC = PageFactory.initElements(driver,                            EfroTechCareers.class);  
           eTC.formFillCareers();  
           if (eTC.verifyFormReset() == true)  
           {  
                System.out.println("All fields are reset to defaults");  
           } else  
                System.out.println("Some fields are not reset to defaults");  
      }  

 }


The above scenario of the scripted/automated tests can be used to solve the problem we started with discussion in this post. The test can be repeated as many time as the need arises. Its value keep increases and cost decreases as many time we execute the tests.

What approach you take while automating the test. Do share here if it is worth sharing.

Monday, April 28, 2014

Control Identification Problem Due to IFrame in Selenium WebDriver

Problem

I have been learning Selenium with my own interest by finding the helpful resources online. This time I picked one of the website that has a form, submit button and a reset button for automation script and testing the Reset form functionality on the page. After completing the first step of the scripting and getting the locators on the page (http://www.efrotech.com/careers), everything seems fine from the HTML that looks pretty neat because every control can be uniquely identified with ID locators. When I run the run the script (for understanding just writing couple of lines) Selenium WebDriver throws the dirty exception of NoSuchElementPresent.

                new Select(driver.findElement(By.id("ddlJobs"))).selectByVisibleText("QA Engineer");
                driver.findElement(By.id("txtName")).sendKeys("Muzaffar");

After trying this simple locator and one by one all the locators like CSS, XPath the same exception is thrown after each run.

Solution:

After posting the problem to the internet one of the guy Nitin Chawda from Kony Labs Hyderabad pointed the issue that the controls lie within the IFrame so the IFrame control must be identified first before the manipulation of the controls on the page and within IFrame. So the script would like this

             driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[height='520']")));
new Select(driver.findElement(By.id("ddlJobs"))).selectByVisibleText("QA Engineer");
driver.findElement(By.cssSelector("input#txtName")).sendKeys("Muzaffar");

To see complete code snippet please click here (not now but in next few days :) ).

Friday, April 18, 2014

Finding and hunting bugs - Storefront Inc.

I was asked to navigate to the URL "http://storefront-staging.herokuapp.com/qa_testerss" and was asked to report the the bugs/error on the page. I manage to find few, can you share yours hunts from the above URL? do write in comments.

Storefron Inc. custom error page.