Sunday, November 30, 2014

Transforming a line item



Extending the World class is one way to extend the functionality of Cucumber. In this section we will
look at another. In a few of our step definitions we have specified that we wanted to use a specific
“line item”. In those steps we had to always take the String Cucumber passed and convert it to a
number using the to_i method. If we want Cucumber to automatically convert it for us we can use
a Transformation. Let’s look at that now.
                                        The first thing we need to do is create a new file in the support directory named transformations.rb. The file name doesn’t matter; I just like to collect all of my transformations in the same file. On a typically large project you might see up to five or six transformations. In this file we will create our first transformation:

  Transform /^line item (\d+)$/ do |line_string|
   line_string.to_i
  end


This structure should look familiar. It is very similar to step definitions except it begins with the
word Transform instead of Given, When, or Then. To break it down completely, what we are saying
with this code is find a capture group of a step definition (portion of a step definition surrounded by
parentheses) that contains “line item” plus a number and perform the following action on the value
of the number. In order for this Transformation to find the appropriate step definitions we will need
to move the opening parentheses to surround the entire match.

Then /^I should see "([^"]*)" as the name for (line item \d+)$/ do |name, lin\
e_item|

Now we no longer need to convert the line_item parameter to a number since the Transformation
takes care of this for us.

       This technique is very useful when you have values that need to be converted and you wish to move
the logic from multiple steps to one Transformation. For example, imagine you need to perform a
lot of date handling. It would be nice to say things like today, tomorrow, or yesterday and have a
Transformation object create a date object.

Source: Cucumber and Cheese book

Friday, October 17, 2014

How to Instrument Android App apk file



1.   Download apk file.
2. 

Wednesday, September 3, 2014


How to automate testing of display of a site for different devices by means of Galen Framework

Refer: 

http://sysmagazine.com/posts/203506/

http://galenframework.com/docs/reference-galen-spec-language-guide/#Comments

Sunday, July 27, 2014

Generate Videos during Test Automation


I understand that videos play an important role in Test Automation. Some people think that videos
are not so much important in test automation, but my experience taught me that even videos give you lot of information that lets every one knows what happens during test execution, and other information that happens during test execution.

   Here, I would like to explain a very simple mechanism to have your scripts generate videos of your test scripts. We know that capturing videos are little tricky and need to depend on some third party tools. Here is a third party freeware/open source  using which we can have the videos generated for our scripts.
The example I describe would be in php as some people do not get an idea how to capture videos using php, as php is not flexible to use like other high level languages such as C#, Java, etc.,

FFMpeg is an command line tool using which we can generate videos. And I do not want to describe a lot here, to let readers do their task immediately.

download the ffmepg from the link: http://ffmpeg.zeranoe.com/builds/
once you download the build extract the file and put ffmpeg.exe in your system path you define in Environment variable. example: C:\DriverCapture is my path  i define in System environment varible "Path".
And then, write the command
command: ffmpeg -f dshow -i video=\"screen-capture-recorder\" -r 5 -threads 0 testMethod1.wmv
in your phpfunction. Now use shell_exec(command) to launch the video.

example: 
 public function StartVideoThreadForTest($testMethodName)
    {
        //Run the Command to Start running the video without CaptureVideo.exe
        $cmd="ffmpeg -f dshow -i video=\"screen-capture-recorder\" -r 5 -threads 0 ".$testMethodName.".wmv";
        shell_exec($cmd);
    }

Now call this method before your test runs. To stop the video capture use the following command to stop:
shell_exec('taskkill /F /IM ffmpeg.exe');

But, When you run your script you observe that your execution does not move from video launch command, to make it work.
Create a .NET console project and put the following code in the Main method.
namespace CaptureVideo
{
class Program
    {
        static void Main(string[] args)
        {
            Process ffmpeg = new Process();
            ffmpeg.StartInfo.FileName = "c:\\seleniumDrivers\\ffmpeg";
            ffmpeg.StartInfo.Arguments = " -f dshow -i video=\"screen-capture-recorder\" -r 5 -threads 0 -y "+args[0]+".wmv";
            ffmpeg.Start();
        }
    }
}
In the above program I put the ffmpeg in the c:\seleniumDrivers\ folder.
Compile the above program, you will see an exe (CompiledVideo.exe - project name) generated inthe debug folder. Noe put the compiled exe in the system path you used to place ffmpeg directory.
And now use the following php function to run the video recorder on background:

 public function StartVideoThreadForTest($testMethodName)
    {
        //Run the Command to Start running the video without CaptureVideo.exe
        //$cmd="ffmpeg -f dshow -i video=\"screen-capture-recorder\" -r 5 -threads 0 ".$testMethodName.".wmv";
        $path=__DIR__.'/../../../Output/';
        $cmd="CaptureVideo ".$path.$testMethodName."-".time();
        shell_exec($cmd);
    }

Tuesday, July 22, 2014


Download Auto IT installer and install it on your windows machine.

Write the following code to your Auto IT Script Editor.:

Code:
opt("MustDeclareVars", 1);0=no, 1=require pre-declare

Main()


Func Main()
  
    Local Const $dialogTitle = $CmdLine[2]
    Local Const $timeout = 5

    Local $windowFound = WinWait($dialogTitle, "", $timeout)
    
   
    $windowFound = WinWait($dialogTitle, "", $timeout)
    Local $windowHandle

    If $windowFound Then
       
        $windowHandle = WinGetHandle("[LAST]")
        WinActivate($windowHandle)
   
        ControlSetText($windowHandle, "", "[CLASS:Edit; INSTANCE:1]", $CmdLine[1])
        ControlClick($windowHandle, "", "[CLASS:Button; TEXT:&Open]")        
        
    Else
     
        MsgBox(0, "", "Could not find window.")
        Exit(1)
     EndIf
EndFunc    


And then Go to Tools and Compile which generates exe file that can be used in any language binding.

To upload multiple files in windows environment use the following example syntax :



C:\Users\User1Name\Documents>FileUploadScript.exe Open C:\Users\ddefilippo\Pict
ures\"{space}""'Image1"""{space}"""Image1- Copy"""

Monday, July 21, 2014

The agent was stopped while test was running in Visual Studio



It is known issue that we come across "The agent was stopped while the test was running" message during our testing.  There is a bug that still active at Microsoft. To get rid of this, there is a resolution. This is very simple as such adding a key to your QTAgent/app.config file.

Just add :
<legacyUnhandledExceptionPolicy enabled="1"/> to your QTAgent.config file in <runtime> 
section or just runtime section to your app.config and put this enabler into that section.

This resolves you the problem of seeing this agent stopped message. 
Reference:
1. http://msdn.microsoft.com/en-us/library/ms228965.aspx
2. https://connect.microsoft.com/VisualStudio/feedback/details/556702/
unit-testing-the-agent-process-was-stopped-while-the-test-was-running


Wednesday, July 16, 2014

Enable XDebugger for PHP using XAMPP

After installing Xampp on windows, make the following settings in the php.ini file to configure Xdebug for your IDE.

Open php.ini file under <Xampp_Home>\php directory, for editing.
  • Note: <Xampp_Home> is the location of Xampp installed. eg: C:\Program Files\Xampp refers to <Xampp_Home>.

Find & uncomment(ie., remove semicolon(;)) from the following lines,


zend_extension="<Xampp_Home>\php\ext\php_xdebug.dll"
xdebug.remote_host=localhost (change 'localhost' to '127.0.0.1')
xdebug.remote_enable=0 (change '0' to '1')
xdebug.remote_handler="dbgp"
xdebug.remote_port=9000

Save php.ini & restart the computer.

SetUp Your PHP Selenium Test Project with XAMPP

To Setup the Php Test project with Selenium the following are required:
1.       PHPStorm IDE by Jet brains: http://www.jetbrains.com/phpstorm/
2.       Xampp for Downloading the “PHPUnit” and “PHP Interpreter”. XAMPPhttps://www.apachefriends.org/download.html
        Installing PEAR & PHPUnit with XAMPP
1.        Once you install the Xampp server, launch the XAMPP control panel and start the Apache Server.
Note: If you have Skype or any other application that uses the port 443 then change/reconfigure the Xampp default port.
XAMPP Control Panel

2.        Start the Apache Server Now by clicking the Start button under Actions. Then you should see status message and the port info on which the server is running.
3.        Now Click on Shell button in the XAMPP control panel. Then you should see the XAMPP Admin Console.
4.        Now, go to http://pear.php.net/go-pear.phar and download pear file to download and configure PHPUnit.
Once you download the .phar file place the file in C:\XAMPP\Php folder
5.        In the Console navigate to XAMPP php folder using command line:
# cd c:\xampp\php
and then use the command to install the pear file
# php go-pear.phar
And press Enter.
Then the following should be displayed.
“Are you installing a system-side PEAR or a local copy?
<system|local> [system]: system
And press Enter twice.
6.        Now the PEAR file should be installed on your local at system-wide. And you should see the following message.
7.        Run the C:\xampp\php\PEAR_ENV.reg file created to import your PEAR environment variable settings. This is not a mandatory task(recommended to avoid this Registry setting)
A Confirmation should be displayed up on clicking the Registration file
Click Yes. And you should see the following Information message box.
8.        Log out of Windows and back in - This will load the new environment variables into memory (otherwise the old location for pear.ini will be used).  Confirm your settings by running:
# pear config-show
It should show “C:\xampp\php\pear.ini” for User Configuration File.
9.        Now, install PHPUnit & Skeleton Generator through PEAR using the following commands
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
pear install phpunit/PHPUnit_SkeletonGenerator

10.     Check your version of PHPUnit - It should be at least version 3.6.x
phpunit –version

You should also now have phpunit-skelgen.bat in the C:\xampp\php folder.
Netbeans NOTE:
Netbeans to do unit testing in PHP refer: http://netbeans.org/kb/docs/php/phpunit.html#installing-phpunit

Install PHPUnit Selenium Extension:
1.        Use the following command to install PHPUnit Selenium Extension
Pear install phpunit/PHPUnit_Selenium

Install PHP Interpreter:
1.       Download Php Windows Installer from the website: http://php.net/downloads.php
2.       Extract the Zip file and copy the extracted folder to xampp folder.


Setting Up the PHP Project:
1.        Launch the PHPStorm IDE that you installed.
2.        Click on Configure and Settings.
3.        Click on PHP Tree Node and Select the Interpreter from Browse dialogue. And then choose the extracted folder path for the interpreter.
Then you should see as below in the Settings window.
4.        Now from the include path add the location paths for referring the pear and php unit. Add the following paths by clicking ‘+’ symbol.
<!--Also include the following which I forgot to add before
C:\xampp\phpMyAdmin
C:\xampp\php-5.5.14-nts-Win32-VC11-x86-->
5.        Apply the above values to include path for references. Now click the PHPUnit tab and select the configuration file that contains the list of tests.
6.        Now go back to Home Page and create a new PHP Project if you do not have an existing php project or use Open Directory to open the existing project.
7.        Assume you have existing project. So use Open directory to open the Project. Now Configure PHP Include Paths to External Library.Click Ok in the configuration window, because you have already configured at the startup.
8.        Now Edit Configuration under Run Menu. Create A New Configuration “PHPUnit” and LoginTest as below
9.        Click Ok and Run the Test Class as shown. Before you run your test start the Selenium Standalone server using command prompt.
Go to the location where the Selenium server is located:
Example:
The selenium standalone server is in c:\seleniumDrivers
In command prompt
Cd\
Cd seleniumDrivers
Java –jar selenium-server-standalone-2.42.2.jar





Running Tests On Multiple Browsers:
To run the tests on multiple browsers change the browser name in setup method.
For
 Internet Explorer use: “internet explorer”
 Firefox use: “firefox”
 Chrome use: “chrome”
 Note: Before you make the changes make sure you have the IE and Chrome Driver downloaded in your local directory.
 Download the drivers from http://seleniumhq.org
 After downloading the drivers keep them in a fixed directory say: c:\seleniumDrivers
 And the set this path in Environment variable (variable Name: Path).

Example:
   $this->setBrowser('internet explorer');




Friday, July 4, 2014

Analyze CodedUI Test Logs

It is best practice to enable Test Logs in any Test Automation tools to better understand the test results to provide immediate solution if you face any problem in your execution. So, like the other tools CodedUI also provides test log tracker to provide us the stack trace of the test result.  To enable this feature we can follow 3 ways:

1. Configure your QTAgent config file:  

This is a traditional method. In this method you set the configuration options in the QTagent file. 
In older versions of visual studio we have keys that sets the test log for out tests.
<add key="EnableHtmlLogger" value="true"/>
<add key="EnableSnapshotInfo" value="true"/>

Add these 2 keys to your QTAgent.config file in the IDE directory
<C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE> for 64 bit machines under system.diagnostics node.
In the latest versions of visual studio these 2 keys are depreciated into a single key
as
<!-- You must use integral values for "value".
Use 0 for off, 1 for error, 2 for warn, 3 for info, and 4 for verbose. -->
<add name="EqtTraceLevel" value="0" />
This you find when you open QTAgent32.config file. And it is wise to choose the appropriate config file based on the
.NET framework you use in your test project.
This settings provides you HTML reports, and stack trace of the test result if the test fails.

2. Configure these settings in your app.config file:
If you are confused in identifying the appropriate QTAgent.config file, you better add these settings in your app.config file without disturbing your QTAgent.config file. This will override the settings provided in your QTAgent.config file.

Add the following settings to your app.config file under configuration node:
<system.diagnostics>    <switches>       <add name="EqtTraceLevel" value="1" />      </switches></system.diagnostics>
Update the EqtraceLevel based on your need.o: Off1: Error2: Warn3: Info4: Verbose

3. Add this setting in your test Code:Add the following code to your test code with out disturbing your QTAgent config file and app config filePlayback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;

To know more about Test Log analyzing refer the msdn: http://msdn.microsoft.com/en-us/library/jj159363.aspx

Selenium Tutorial - First Selenium Test


I agree that the Selenium is the best web test automation as per current market standard. Since the power of selenium makes your test directly communicate with web browser dom with any window identification dependency like other tools do. Let us start writing our first selenium script with c#.

Before , you start writing your selenium script you first must understand your requirement and what to do and what not to do.
It is always recommend to understand the API before you start writing selenium scripts.

Example Script:

   Scenario: Search a blog in <yuvarajatcts.blogspot.com> and read the content in the blog.

   Design:  To start your script, let us just go by considering some manual steps to achieve our goal(reading      content).
    1. Launch Browser Window.
    2. Navigate to the specified URL.
    3. Identify the Search text box and type the query.
    4. Wait for the post to load and read the content.

   Now, let me explain how we write the code automate our manual scenario.

  Step1:
             Launch WebBrowser: You can launch your webBrowser using selenium classes.
              Example: 
               IWebDriver driver=new FirefoxDriver();
               driver.Navigate().GoToUrl("http://yuvarajatcts.blogspot.com"));
  
    The above code launches Firefox browser with the Blog page navigated to. If you want to launch the   application in chrome then use "driver=new ChromeDriver()"" , in IE driver=new InternetExplorerDriver();.


Step2:
   Identify the Search text box and type the query. Now let us take the web application and get the search  text box object properties. This can be achieved with different tools/ plugins. Some of them are Firebug for Firefox, Inspect Element for chrome and Firefox, Developer Tools for IE. So, it is up to you based on your convenience and ease.

Assume, you text box has "<input type='text" id="searchTextBox"> </input>
To identify the above text box , you can write the following code:

    IWebElement searchTextBox=driver.FindElement(By.Id("searchTextBox"));

Note, the return type of FindElement is IWebElement interface.

Step3:
Once you identify the object, perform action on the control you identifies, such as Mouse Click, Keyboard Press, etc.,

So, I just call

       searchEdit.SendKeys("this is sample"); 
 Then, Press enter to wait till the page loads

searchEdit.SendKeys("{Enter}");

So, You can put the above code into TestMethod as follows:

Selenium Test Example:

[TestMethod] 
public void TestSelenium()
{
   IWebDriver driver=new FirefoxDriver();
   driver.Navigate().GoToUrl("http://yuvarajatcts.blogspot.com");
   IWebElement element=   driver.FindElement(By.Id("searchTextBox"));
   element.SendKeys("this is simple");
   element.SendKeys("{Enter}");
}