Monday, July 14, 2014

How To Configure Jenkins With Selenium Projects


Till date it was gray matter to me, how to configure Selenium projects with Jenkins. I tried on my own and somehow set it up. But this video is superb to watch.It cleared all my doubts regarding Jenkin's and Selenium project setup.
Important links-

  • http://jenkins-ci.org/
  • http://docs.seleniumhq.org/download/

Thank you Software Testing forum for this lovely video.





Monday, May 19, 2014

Groovy What Is It??


Groovy is a language to start with but it is a super version of Java which can use all Java's enterprise capabilities with some other extra features.

It cam be used for code coverage. It is having various libraries for mocking[3rd party and built in].

It supports

  • Hudson
  • Teamcity
  • Anthilpro to call a groovy code
  • Code narc for code code Matrics
  • ANT,Maven,GMaven,GANT,Cradel like Build tool

Groovy=Java-Boiler plate code
+ Optional dynamic typing
+Closures
+Domain Specific Language
+builders
+metaprogramming
+Object Oriented
+Optionally typed
+Support Operator Overloading
+Multimethods
+literal decleration for List
+Support for maps,ranges,regular expressions
+Efficient Object Navigation
+Supports of Groovy Bean
+Grep and Switch
+Template builders
+Supports CI[Continuous Integration]
+Supports Build tools

When Java imposed lot more restrictions around itself,Groovy came to fill up the limitations of java.The moto of Groovy are-

  • Write once use anywhere
  • Automatic memory management
  • dynamic nature that gives users the options to modify code,augment the code,change the pattern of the code during run time/compile time
  • Works on JVM
Similar languages to Groovy are
  • Jython
  • JPearl
  • Scala
  • Clojure
  • JRuby
  • Small Talk
Now some advantages of Groovy:
  • Easy to learn and Develop
  • Good candidate if the application is built on Java
  • Mostly use inside JVM that bypasses the GUI[Mainly used to bypass GUI and create testdata]
  • Support polyglot Language
  • Easy,plug and play

Few disadvantages:
  • Need JVM
  • Less useful if the UAT is developped in .NET,phython,PHP
  • Ruby is a close competitor
Thursday, May 1, 2014

How To Install Groovy In Windows


Where do we get Groovy?
Here--http://groovy.codehaus.org/Download
take the latest Binary Release . Download that one as zip.


Unzip the zipped content. It looks like the below screen shoot:
Now how to run the groovy..
1. Open the cmd.
2. Navigate till to the path where the Groovy is installed.
3. Go to the bin folder
4. write groovyConsole in cmd.
5. It will open the console [Screenshot given below]





Now for this way,we always need to navigate to the installed folder and give the command. The second way , which I like is to add them to the path. Create a path variable called GROOVY_HOME.

  1. Press Windows + Break key combination
  2. Click on Advanced System Settings
  3. It will open System Properties
  4. Click on Advanced Tab.
  5. Click on Environment Variables.
  6. Go to System Variable section. Click on New... button
   7. Find the Path variable in the list of system variables and append or insert the %GROOVY_HOME%\bin; string to it

Just open command from
and give command as groovyconsole.







Thursday, April 24, 2014

Microsoft VBScript runtime error: ActiveX component can't create object


Very recently I am facing this issue with one of the test machine. The DOS prompt says Microsoft VBScript runtime error: ActiveX component can't create object.

I have the following code:
Dim qtApp
Dim qtResultsOpt
Dim qtTestdir, resdir
Dim Shell

Set Shell = CreateObject("WScript.Shell")
qtTestdir =my test path
resdir ="my result path"
Set qtApp = CreateObject("QuickTest.Application")
If Not qtApp.Launched Then
  qtApp.Launch
End If
qtApp.Visible = True
qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open qtTestdir, True
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep"
Set qtResOpt = CreateObject("QuickTest.RunResultsOptions")
qtResOpt.ResultsLocation = resdir
qtTest.Run qtResOpt
qtTest.Close
qtApp.quit
Set qtResOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing


it was throwing error on the line no=10 that is Set qtApp = CreateObject("QuickTest.Application"). In the DOS prompt the error was pretty clear.
As usual , Google came all the way with bunch of suggestion distributed in different pages!!. I am just summarizing what I followed..

I just updated the code like

On Error Resume Next
Set qtApp = CreateObject("QuickTest.Application")
Msgbox Err.Number 

But to my surprise, it did not work. Some asked to increase the time as wait between the execution

On Error Resume Next
WScript.Sleep 5*60000
Set qtApp = CreateObject("QuickTest.Application")
Msgbox Err.Number 

Even that did not work.Then I googled more and found more suitable solutions.
1. Restart machine
2. Disable firewall and check
3. This is due to timing issue of creating ActiveX component object,when it is taking more time to open QTP more time like-5 mins.It gives me error in the line "Set objQTP = CreateObject("QuickTest.Application")" itself, before coming to line objQTP.Launch.And after the error it closes the QTPro.exe and QTAutomationAgent.exe processes that has been created due to CreateObject method, and objQTP is becoming null.
4. if it is Windows Vista Client you need to install QTP correctly.
  • Enabling UAC
  • Installing as User
  • Start QTP as Admin first.
5. Re register the QTP server using the below command
  • For XP:
    "C:\Program Files\HP\QuickTest Professional\bin\QTAutomationAgent.exe" /regserver 
  • For Windows Server
    "C:\Program Files (x86 )\HP\QuickTest Professional\bin\QTAutomationAgent.exe" /regserver 
Till now I had no success...what I thought that might be the QTP process had not been closed by the code. So I modified my code little bit..
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'QTPro.exe'" 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next 
I thought that it was the end of problem!!!

But to my bad luck, it did not work....Still I was getting ActiveX component can't create object error.

One of friend said to re-register the VBScript.dll
1.Open Command prompt from Run
2.Type regsvr32 %SystemRoot%\system32\VBScript.dll
3.Click on Enter
This is how we should re-register the dll file. or register the WScript object by running the wscript -regserver command from a command prompt or from the Run command on the Start menu
I was not convinced with the solution as I was not getting any error code.Interestingly at this point I hadm noticed that QTPro.exe was actually in the task manager. So QTP was actually running in the backend but not coming in the front. Problem became very complex at that time.

At this point of time an article published here,looked resolve my problem..

I recently helped someone who had the same problem, but with a VB Script application, executed with cscript.exe. This VB script application uses a 32-bit COM object and failed to run on a 64-bit OS. The error, Microsoft VBScript runtime error: ActiveX component can't create object: 'XXXXXX'.

To fix the issue, the script must be executed with the right executable. There are two cscript.exe in the 64-bit OSes. One is located at %WINDOWS%\System32, and the second one is located at %WINDOWS%\SysWOW64.

The one under System32, is a 64-bit version. The one under SysWOW64 is the 32-bit version. Run the VBS application using the 32-bit application.

Why System32 contains 64-bit binaries, and SysWOW64 contains 32-bit is another story, but there is a very good reason behind it, backward compatibility. :)
As I had no other choice, I tried to start QTP with this approach only. But !!!!! Still It was failing!!!!.

Suddenly I saw a pop up silently seating in the task bar. Very humble, it was saying there were 12 updates and needed restarts.Company policy needed to be updated.

I just allowed them to get installed..restarted 3 times...It worked like champ. VBS started wroking.
Sunday, March 2, 2014

Rakuten to Buy Internet Messaging App Viber for $900 million


After whats App it is the turn of Viber!!!!!. Yes...Rekuten is buying Viber for $900 M. The E Commerce giant of Japan confirmed. The aim is to be the number one internet service company. Hence they are making lot of purchase--

Rakuten's purchase of the messaging and VoIP company follows its acquisitions of Canada's e-book platform Kobo, Spanish video service Wuaki.tv, and Viki, a digital content platform.

The Viber app is available for

  • iPhone
  • Android phones 
  • tablets
  • Windows Phone
  • Blackberry
  • Windows
  • Windows 8
  • Mac
  • Linux
  • Symbian
  • Nokia S40
  • Bada devices over 3G/4G or Wi-Fi connections.
Sunday, February 23, 2014

When Frame.pack method Can Be Used While Designing Swing Desktop Based Application?


This article is based on my experience and a leaning on swing application. I was designing a desktop based swing application with some JTextfields,JButtons some picture which were hidden in nature. Based on some selection or some data they needed to activate.I was using the below code

frame.add(container);
frame.setVisible(true);
frame.setSize(1200, 300);
frame.pack();

But when user tried to enter some data and based on the action like focus out some image got displayed.
public void focusLost(FocusEvent e) {
    // TODO Auto-generated method stub
    image.setVisible(true);
  }});

    
This time, to my surprise frame could not resized and could not show my image.I had to drag the frame [manually resize].
But if was printing frame's height and width by..
 System.out.println(frame.getHeight());
 System.out.println(frame.getWidth());  
It was actually printing 1200 and 300 which I set before. But effectively It was showing something 200*400 frame.I started analyzing and tried o find out the root cause of the problem. Then I found the the actual cause ...It was the frame.pack() method which was causing the problem.When I commented the step It worked. But open a very big ugly frame of 1200*300.
Ok...the next question could be when should we use frame.pack()???

The probable answer was when your frame is fixed in size and you were not expecting new element will be visible in the same frame,pack() was the right method to call.

it calculated the actual width and height based on the frame's all visible properties..say I had a visible JTextField of size (height=5 and width=20) and a button of size (height=5 and width=40).If they were in default flowlayout then frame tried to enter both of them in the same line whose height will be 5 and width60.
[even if I had asked to resize the frame to 1000*300 it opened height of 5pix and 60 pics.]Pack method to make the smallest space in a frame so that They can be useful

Below are the great tutorials:
http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
http://wiki.answers.com/Q/What_is_pack_method_in_java_programming?#slide=1



Sunday, February 9, 2014

What Is The Meaning Of Wining --IndiBlogger Organizes Blogging Contest.


IndiBlogger organizes great blogging contest for great minds.The topic is very unique and attractive.
What is the meaning of wining to you?
Apart from prizes, participants will get a chance to meet the speaker..
The Speakers are--

  • Vasundhara Raje
  • Adrian Levy
  • Amitabh Bachchan
  • Anil Agarwal
  • Arun shourie
  • Deepika Padukone
  • Henrik Schafre
  • Roger Cohen
  • Aatish Taseer
  • Jairam Ramesh
  • Jack Sim
  • Maysoon Zayid
  • Hooman Majid
  • Kalki Koechilin
  • K. Radhakrishnana
  • Jean-Yves Le Gall


Award??
Yes there are cash award too. you can get a chance to get 1 lakh cash.
Interested?? Please visit here for more.http://www.indiblogger.in/topic.php?topic=101
Monday, February 3, 2014

Page Object Pattern Major Drawback in Selenium- A nice Video to watch


This is a nice video, I have found in youtube.it describes the biggest drawback about Page Object pattern of Selenium..

How To Resolve IllegalStateException for IEdriver in Selenium


This is a very common problem and I found the solution while doing a preliminary checklist.

Well, this problem occurred when my friend tried to execute his first selenium script with IE.

As per code concern he has used..


System.setProperty("webdriver.ie.driver","C:\\Perl64\\bin\\IEDriverServer" );
InternetExplorerDriver d3 = new InternetExplorerDriver();
d3.get(http://gmail.com);


With this he got the below written exception..


Exception in thread "main" java.lang
.IllegalStateException: The driver executable does not exist: C:\Perl64\bin\IEDriverServer
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)


Its complaining that the IEDriver does not exist  "The driver executable does not exist: C:\Perl64\bin\IEDriverServer"

Now question is how to solve this problem, well..while doing a preliminary check list I found the basic problem i.e like most of us he forgot to add .exe in the driver.  i.e.--

System.setProperty("webdriver.ie.driver","C:\\Perl64\\bin\\IEDriverServer.exe" );
InternetExplorerDriver d3 = new InternetExplorerDriver();
d3.get(http://gmail.com);


This code worked fine.
Tuesday, January 28, 2014

Nokia Organizes Idea 2 App Contest With Great Prizes To Win


Aspiring to have a big screen Lumia 1020 experience? Devworx is delighted to announce Idea to App contest where you can win one! Participate now to win!
Nokia Lumia 1020, Nokia Lumia 520, Digit Subscription, Gift Vouchers, 1500 Experiance Points and many more assured prizes to be won!
So what are you waiting for? Go ahead and register now!
Weekly Prizes * :
  • 1 x Nokia Lumia 1020 per week: Early App Submission during the week. 1 lucky entries will be shortlisted.
  • 5 x Nokia Lumia 520 per week: Early App Submission during the week. 5 lucky entries will be shortlisted.
  • 3 x Rs. 1000 GVs each week: The top 3 users who share the contest page on Facebook tag the contest AND tag with #idea2app.
Assured Prizes:
  • Digit Subscription for 3 months: Get free 3 months Digit Subscription worth Rs. 650/-
Overall Prizes:
  • 10 x Nokia Lumia 1020: 10 winners to get 1 Nokia Lumia 1020 each.
  • 1500 Experience Points: You will get 750 points for each app that you develop upto a maximum of 2 apps. The points could be redeemed for some really cool, exciting prizes and additional prizes.

Monday, January 27, 2014

How To Avoid Selenium Crash While Sending A Huge Text Using SendKeys?


sendkey is a very useful and most frequently used command while developing test through java and Selenium.
But recently I have seen Selenium viz underlying browser [like-Mozilla Fireox mainly] hangs when I try to send more than 1000 characters.

let us assume I have a note to process.There is a textarea in the application which will accept 2500 characters. Now the code I have tried..


WebElement test = driver.findElement(By.id(TXT_APPT_NOTES));
test.sendKeys(ApptNotes);


if the ApptNotes is more than 1000 character , selenium viz Mozilla Firefox hangs.
So what could be a good solution--
Well there is something called clipboard Which is capable of storing huge text or information.I came across a nice post from java practices[http://www.javapractices.com/topic/TopicAction.do?Id=82]. This gave me an instant idea about how to overcome this problem.

We have to code accordingly and need to use this nice feature..


let me go step by step...


import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class TextTransfer  implements ClipboardOwner{

 public static void main(String[] args) {
  TextTransfer textTransfer = new TextTransfer();
  WebDriver driver=new FirefoxDriver(); 
  Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
  //Copying huge chunk of code to clipboard
  WebElement test = driver.findElement(By.id(TXT_APPT_NOTES));
  textTransfer.setClipboardContents(test.getText().toString());
  
   }

 private void setClipboardContents(String text2Copy) {
  // TODO Auto-generated method stub
   StringSelection stringSelection = new StringSelection(text2Copy);
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     clipboard.setContents(stringSelection, this);
  
 }

 @Override
 public void lostOwnership(Clipboard arg0, Transferable arg1) {
  // TODO Auto-generated method stub
  
 }
}
This code will copy the huge text into clipboard.
Now getting text from clipboard is having two ways..

use sendkeys and without using sendkeys

Using sendKeys function.
say I want to set it to a webElement
WebElement test = driver.findElement(By.id(TXT_APPT_NOTES_2));
test.sendKeys(ctrl+v)

The second approach where we will not use the sendkeys..


public String getClipboardContents() {
      String result = "";
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      //odd: the Object param of getContents is not currently used
      Transferable contents = clipboard.getContents(null);
      boolean hasTransferableText =
        (contents != null) &&
        contents.isDataFlavorSupported(DataFlavor.stringFlavor)
      ;
      if (hasTransferableText) {
        try {
          result = (String)contents.getTransferData(DataFlavor.stringFlavor);
        }
        catch (Exception ex){
          System.out.println(ex);
          ex.printStackTrace();
        }
      }
      return result;
    }
The entire code will be like below:

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class TextTransfer  implements ClipboardOwner{

 public static void main(String[] args) {
  TextTransfer textTransfer = new TextTransfer();
  WebDriver driver=new FirefoxDriver(); 
  Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
  //Copying huge chunk of code to clipboard
  WebElement test = driver.findElement(By.id(TXT_APPT_NOTES));
  textTransfer.setClipboardContents(test.getText().toString());
  //getting the huge text from clipboard
  String getClipboardText=textTransfer.getClipboardContents();
   }

 private void setClipboardContents(String text2Copy) {
  // TODO Auto-generated method stub
   StringSelection stringSelection = new StringSelection(text2Copy);
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     clipboard.setContents(stringSelection, this);
  
 }

 @Override
 public void lostOwnership(Clipboard arg0, Transferable arg1) {
  // TODO Auto-generated method stub
  
 }
  public String getClipboardContents() {
      String result = "";
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      //odd: the Object param of getContents is not currently used
      Transferable contents = clipboard.getContents(null);
      boolean hasTransferableText =
        (contents != null) &&
        contents.isDataFlavorSupported(DataFlavor.stringFlavor)
      ;
      if (hasTransferableText) {
        try {
          result = (String)contents.getTransferData(DataFlavor.stringFlavor);
        }
        catch (Exception ex){
          System.out.println(ex);
          ex.printStackTrace();
        }
      }
      return result;
    }

}
hope that helps!!

Sunday, January 26, 2014

Why Xpath Is Slower in Browsers Specially In Internet Explorer?


This question is asked in a forum. All most all the selenium developers try to avoid to use xpath. They use only in one condition if at tall they don't find any other locator correctly.
I was reading articles on this, and I found

I request all of you to go through these links.
So it is not good to blame xpath. It is the version of the browsers and how they are rendering the Xpath.The report clearly shows that IE-9 onwords xpath is not that slow.The performance difference is slightly in favor of CSS for non-IE browsers and slightly in favor of XPath for IE browsers. 
I will keep updating this page for any other input.