My Blog List

Tuesday, April 19, 2016

Sample Cucumber with Java

Most of us should have heard about the term BDD - Behavious Driven Development. In this post, I would like to give some intro about familiar BDD framework called Cucumber and why we need BDD.

Why BDD?
Once people started moving to Test Driven Development (TDD), it helped a lot interms of reducing the bugs in development stage itself as every feature was developed by creating smaller unit tests, making it FAIL and coding the functionalities to make it PASS.

But eventually, the BAs and testers are not able to follow these testing practices and thus gap in communication which lead to lot of mis-understanding the features/requirements.

So, experts wanted a framework which should take inputs like normal people speaking English and should run the tests based on those requirement. Also this requirement will support as documentation of features to understand by testers/BAs/devs. Thus BDD was born.

BDD keywords:
Given, When, Then and And

Example:

Scenario: Login to Facebook
 Given Facebook login page
 When I enter valid username and passowrd
 Then I should see my home page
 And I should see my name

If you see above scenario, this will act as requirement as well as documentation. We are using this feature scenarios and connecting each steps to our own selenium steps written in java or any other language and running it.

To understand the .feature files and options that we can use for different way of execution, control, etc., read this documentation.
https://cucumber.io/docs/reference

You can find the sample project and start learning on your own.
https://github.com/SCSVEL/SampleCucumber-FB

Friday, April 15, 2016

Continuous Integration, Testing and Delivery

Based on the knowledge gathered from QA and DevOps experts, presenting a simple graphic which represents how actually the CONTINUOUS delivery works. Also this will help to differentiate each from other.



Monday, March 28, 2016

Selenium - TestNG - Jenkins Integration

As current agile development process keep on expecting more testing with continuous integration stuff, I am going to give brief summary about how we can integrate the CI process with Jenkins.

Pre-Requesties:
1. Your Selenium project
2. Your Selenium and TestNG lib locations
3. Jenkins installed. Ensure IIS in your machine installed and you can access Jenkins Dashboard using http://localhost:8080/

Before creating a job under Jenkins, try to run your selenium tests from command line.

Selenium - CommandLine:

Let's say, you have project called SeleniumProject under C:\Eclipse folder. Assume you have all your JAR files (Selenium Jars, TestNG Jars, etc) under C:\Eclipse\JARs folder.

Now you can prepare your command.

1. Go to Project location
cd "C:\Eclipse\SeleniumProject"

2. Execute your testng.xml suite by setting the requied class path.
java -cp "bin;..\JARs\*" org.testng.TestNG testng.xml

-cp means class path
bin - bin path to look into class files to execute
..\JARs\* - to refer the JARs location and to include all JARs
testng.xml - assumed testng.xml file is under the project folder

Now it should run the tests. If working fine, then you can update the command in Jenkins.

Jenkins Job:

1. Go to Manage Jenkins --> Configure System and set the JDK installation path.
2. Create New Item of type Freestyle project
3. Under Build section, add build step of type Windows Execute Batch Command
4. Provide your commands and Save.
cd "C:\Eclipse\SeleniumProject"
java -cp "bin;..\JARs\*" org.testng.TestNG testng.xml
5. Now you can run and test.

Go to your newly created project and click Build Now. You can see the build process running and see the output.

Monday, June 8, 2015

Handling Objects not recognized as standard type

While doing automation on UI, we will face lot of scenarios like Object not identified as expected type and will scratch our head how to simulate such object set, click, etc.

We have some options to simulate actions on such controls using WScript.Shell or Mercury.DeviceReplay
The only thing, we need to instruct the those APIs at whichposition exactly it need to perform the actions.

You can do with absolute poistion:
x = yourObject.GetROProperty("abs_x") + (yourObject.GetROProperty("width") / 2)
y = yourObject.GetROProperty("abs_y") + (yourObject.GetROProperty("height") / 2)
Set MerRply = CreateObject("Mercury.DeviceReplay")
MerRply.MouseClick x + 5, y, LEFT_MOUSE_BUTTON

You can use relative position:
x = yourObject.GetROProperty("width") / 2
y = yourObject.GetROProperty("height") / 2
yourObject.Click x, y, LEFT_MOUSE_BUTTON

If you want to type on the controls, simulate the type using SendKeys followed by click action.

UFT - Take full page screenshot by scrolling the page


'########################################################################################
'This is navigate through the full page and taking individual screenshot of visible area
'########################################################################################
Function TakeScreenshot
 Dim intScrolls, intScroll, strScrollPos
 Set pgApp = Browser("").Page("")

 intScrolls = Round(pgApp.RunScript("document.documentElement.scrollHeight / (screen.height)"), 2)
 If intScrolls < 1 Then intScrolls = -1

 pgApp.RunScript "window.scrollTo(0, 0);"
 Wait 1
 Browser("").CaptureBitmap "C:\screenshot0.png", True
 For intScroll = 0 To intScrolls
  If Environment.Value("Browser") = "CHROME" Then
   strScrollPos = "scrollY"
  Else
   strScrollPos = "document.documentElement.scrollTop"
  End If
  If pgApp.RunScript("document.documentElement.scrollHeight - " & strScrollPos) > pgApp.RunScript("screen.height") Then  
   intY = pgApp.RunScript(strScrollPos & " + screen.height - 168;")
   pgApp.RunScript "window.scrollTo(0, " & intY & ");"
   Wait 1  
   Browser("").CaptureBitmap "screenshot" & (intScroll + 1) & ".png", True
  End If          
 Next
 
 'To merge the images to generate full page screenshot
 Call MergeImages
End Function

'########################################################################################
'This is to merge all individual images to one full page screenshot
'########################################################################################
Function MergeImages   
    Dim drawImage, grapImage, imgFormat, imgLayer, imgPT
    Set drawImage = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", 1920, 1050)
    drawImage.SetResolution 50, 45
    Set grapImage = DotNetFactory.CreateInstance("System.Drawing.Graphics").FromImage(drawImage)
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot0.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 0)
    grapImage.DrawImage Layer1, pt1
   
    Set imgLayer = DotNetFactory.CreateInstance("System.Drawing.Bitmap", "System.Drawing", "C:\screenshot1.png")
    Set imgPT = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", 0, 540)
    grapImage.DrawImageUnScaled Layer2, pt2
   
    Set imgFormat = DotNetFactory.CreateInstance("System.Drawing.Imaging.ImageFormat", "System.Drawing", Nothing)
    drawImage.Save "finalScreenshot.png", format.PNG
End Function


This code is for UFT/VBScript and you can use the same logic by applying different APIs available for SELENIUM or any other tools.

Monday, May 11, 2015

QTP - Object Identification - Prerequesties

While starting a new project or proof of concept or after new QTP installation, we would face the issue in identifying objects as QTP built objects like WinList, WebEdit, etc.; instead everything will be identified as WinObject.

Here are some steps to ensure you did the environment setup RIGHT before start automating.
  • Did you enabled required Add-ins only while launching
  • Did you selected "Record >> Record and Run Settings" - This should be based on what type of application you are working with

Windows app - Windows >> Record and run test on any windows applications.
Web app - Web >> Record and run test on any open browser.

  • Did you tried to launch UFT/QTP and then AUT.
  • If its web, ensure browser zoom level set to 100%
  • Try disabling the protected mode in IE for web.
  • Launch UFT and AUT using RUN AS ADMINISTRATOR
Also see the Object Identification Methods if you are interested.

Monday, May 4, 2015

Handling auto populate, delayed masking and auto select fields

While doing automation, we could have come across the fields which will do the functionality like,
1. While entering some text, it will auto populate the matching values
2. While entering the text, it will mask the values i.e. convert to xxx.. or ....

To simulate the functionality many of us could have faced problems while entering the values on the field;

  • The value entered is not converting as masking text as it is doing while manual flow
  • The form not accepting the entered values
  • The entered/selected value not persists in the field after the simulation, etc.

How to handle such controls effectively. Here we go;
1. WScript.Sendkeys

Set shell = CreateObject("Script.Shell")
Window("hwnd:=" & Browser("myApp").GetROProperty("hwnd")).Activate  'if it's Browser
obj.Set ""
Wait 1
obj.FireEvent "OnFocus"
Wait 1   
shell.SendKeys "your value", 1000
Wait 1
shell.SendKeys "{TAB}"

The important thing here, always have focus on the current window before passing sendkeys.

2. BLUR
 You can call the blur event after entering the values in the field like;

Set shell = CreateObject("Script.Shell")
Window("hwnd:=" & Browser("myApp").GetROProperty("hwnd")).Activate  'if it's Browser
obj.Set ""
Wait 1
obj.FireEvent "OnFocus"
Wait 1   
shell.SendKeys "your value", 1000
Wait 1
obj.Object.blur 'OR obj.FireEvent "OnBlur"

May be both the approaches will fail or should be better approaches out there, please feel free to share with us.