Friday, July 5, 2019

How to select a suitable Automation Framework?



There are many frameworks available in the market. Before jumping to decide which framework to use or select. Let's see a few questions where people ask on the open forum

Which framework is suitable for branding advertising portals?
Which framework I should use for an e-commerce website?
Which technology I should use to build a framework for a logistic website?
and many more questions...

So, Let's see what are the framework are available in the market

  • Linear testing framework 
  • Modular driven testing framework
  • Data-Driven testing framework
  • Keyword Driver testing framework
  • Hybrid testing framework
  • Behavior-driven development testing framework

What is Linear testing Framework?

The linear testing framework is created in such a way that the test developer writes the code in small methods for each feature and execute it individually. This is a very basic level of the framework and mostly used in the record and play features.  

What is Modular driven testing framework?
In this framework, the test developer creates a small script for each module of the application and call them based on functionality. e.g Login script, Register user script, and Cash Deposit script. These modules are independent of each other and can be called as per functionality flow. In this framework, objects and methods are written in the class file and each class file represents a module of the application. 

What is a data-driven testing framework?
In this framework, the test developer creates a script separately and pass the data from the external file. That means if test developer whats to change the data set then test developer should not change the code or compile the code for new sets of data. Script and data manage separately.  Now the question is If we use data file in the linear and modular driven framework then it won't become data-driven? I would say, Yes, To avoid this you set the data in the code itself. These both frameworks used when you have fewer data and small scale application.

What is Keyword driven testing framework?
In this framework, the test developer defines a keyword to perform actions. e.g Create keyword call CLICK_ON which actually click on the given element. The main feature is your script flow or methods are called based on keyword created. Table creation concept is used while creating this framework.

What is Hybrid testing framework?
When the test developer mixes any two or more frameworks then it becomes Hybrid testing framework. Why test developer do this? For big project and complex scripting, it required to choose Hybrid testing framework. 


What is Behavior-driven development testing framework?
BDD is known as Behavior-Driven Development testing framework. It is very famous when management or Business Analyst involved in the automation result. Report generated in pure English language where BA or management can take a decision on product quality.  


Now, Coming to the main question "How to select a suitable framework Framework?" Framework design or selection should not be done on the product domain. It always creates based on the following criteria:

  • Complexing to the application to test
  • Purpose of automation testing
  • Platform Coverage (Single platform execution or multiple platform executions)
  • The user of the test automation report
  • Resource availability
  • Technical Skill 
  • Test Data Coverage
  • Deadline
Hope this will help you to select a suitable framework for your next automation project.


Friday, June 8, 2018

Create Selenium WebDriver using Java Factory Pattern

Hi Friends,

In Factory pattern, we create an object without exposing the code to the client and refer to a newly created object using a common interface.

This is widely used java pattern for creating the object. 

Here is the UML diagram for creating the webDriver object. 




Click here to download the code from GitHub repo

Note: This is just an idea. Future enhancement can be done based on requirement. 


Thursday, June 7, 2018

Create Selenium WebDriver object using Singleton Java pattern

Hi Friends,

You must be knowing about the java patterns and it's advantage. In this post, I am going to create webDriver object using Singleton java pattern.

Singleton means to define a class that has only one instance and provides a global point of access to it.

Singleton class :


public class WebDriverSingleton {

private static WebDriver driver;
private static WebElement element;

private WebDriverSingleton() {
}

public static void initDriverInstance(Browsers browserName) {
 // code for init driver object
}

public static void openURL(String url){
// open url code
}
public static void quit() {
// code for quit driver
}

public static WebElement findElement(Locator locator, String value) {
// code for findElement 
}

// add all the other required method here
}


Test class :

public class Test_1 {
@BeforeClass
public void Setup() {
WebDriverSingleton.initDriverInstance(Browsers.CHROME);
WebDriverSingleton.openURL("http://newtours.demoaut.com");
}
@Test
public void TestCase_1() {
WebDriverSingleton.findElement(Locator.NAME, "userName").sendKeys("testuser");
WebDriverSingleton.findElement(Locator.NAME, "password").sendKeys("testpassword");
WebDriverSingleton.findElement(Locator.NAME, "login").click();
}
@AfterClass
public void killDriver() {
WebDriverSingleton.quit();
}
}

Click Here to Download code from github 

Wednesday, October 23, 2013

Record objects for CUITe using CUITe_ObjectRecorder


  • Download  CUITe_ObjectRecorder from below link
·         CUITe for .NET v4.5 ( try this and install it – start  CUITe_ObjectRecorder.exe )
·         CUITe for .NET v4


Steps to create CUITe Object
  • Address: Add user which user want to test
  • Click on Record button ( recorder started to record object)
  • Click on User Name, Password textbox and Sign-in button
  • Tool will generate code below application
  • Click on Code icon ( Notepad will open with code)
  • Copy the object code which are generated while recording object
  • Paste in object repository file which created for object repository ( in .cs file)
That’s all, your object repository will be looking like below

  • User has to add following code:
  • ORLogin class should be public– so that class can be use globally
  • Inherit the class ORLogin from CUITe_BrowserWindow
  • If user have created folder for object repository folder then namespace would be display folder name as well

CUITe Configuration

This is small demo for configuring Visual studio 2012 for CUITe, follow the steps to make CUITe work with VS 2012.
 
  •   Install following version of Visual studio
·         Visual Studio 2010 Premium or Ultimate and Feature Pack 2 OR Visual Studio 2012 Premium or Ultimate

  •  Download CUITe Framework from below link
·         This link shows list of projects, from these project use CUITe, CUITe.snk and CommonAssemblyInfo.cs

·         Follow these steps to use UITestPluginForSilverlight dll.
1. Add Microsoft.VisualStudio.TestTools.UITest.Extension.Silverlight from %Program Files%\Common Files\Microsoft Shared\VSTT\11.0\UITestExtensionPackages
2. Added using Microsoft.VisualStudio.TestTools.UITesting.SilverlightControls


  •    Download CUITe.dll from below link
·         CUITe for .NET v4.5 ( try this for VS 2012)
·         CUITe for .NET v4
·         Run above set up and copy CUITe.dll to project folder
·         CUITe_ObjectRecorder.exe - Used for Recording Object for CUITe


  • Install test Agent if user want to run script in other system without installing VS 2012.

Wednesday, June 27, 2012

Example if Bank Table: Insert Query in VBScript


'=================================================================
Create a Bank Table with following fields,
a.       Sr No
b.      Name
c.       Account No
d.      Address
e.      Debit
f.        Credit
g.       Total

Write a script to perform below task.
a.       Write a function to insert a new entry for Debit and it should update total field also.
b.      Write a function to insert a new entry for credit and it should update total field also.
Write a function to update address of user choice Account
'=================================================================

Dim MyConn,cmd,rs
set MyConn= CreateObject("ADODB.Connection")

connectionString = "provider=Microsoft.ACE.OLEDB.12.0;" _
& "data source=D:\bankDB.accdb;Persist Security Info=False;"

MyConn.Open connectionString
Set adx = CreateObject("ADOX.Catalog")
set adx.ActiveConnection = MyConn

initialdebitVal = 0
initialTotalVal = 0
initialCreditVal = 0
userAcctNo = 0
user_exists=false

id=Inputbox ("Enter your Choice 1:debit amount 2:credit amount 3: Change Address 4: New Entry")
Select Case id
case 1: call debitAmt
case 2: call creditAmt
case 3: call changeAddr
case 4: call newEntry
End Select
MyConn.close

function getAmtVals
sInsData = "select * from Bank where Account = " & userAcctNo
MyConn.Execute(sInsData)
Set RS = MyConn.Execute(sInsData)

WHILE NOT RS.EOF
initialdebitVal =  RS("Debit")
initialCreditVal = RS("Credit")
initialTotalVal = RS("Total")

user_exists=true
RS.MoveNext
WEND

RS.Close
set RS = nothing
end function


'function to debit amount from the account entered
function debitAmt

userAcctNo = Inputbox ("Enter the Account number")
call getAmtVals
'validating account exists or not
if user_exists=false  then
msgbox "Account not found"
exit function
end if

debitVal=Inputbox ("Enter the debit amount")

totalVal =   initialTotalVal - debitVal
sInsData = "update Bank  set Debit = " & debitVal & " where account=" & userAcctNo
MyConn.Execute(sInsData)
sInsData = "update Bank  set Total = " & totalVal & " where account=" & userAcctNo
MyConn.Execute(sInsData)
msgbox "Debited Successfully"

end function


'function to credit amount to the account entered
function creditAmt

userAcctNo = Inputbox ("Enter the Account number")
call getAmtVals
'validating account exists or not
if user_exists=false  then
msgbox "Account not found"
exit function
end if

creditVal=Inputbox ("Enter the credit amount")
totalVal =   initialTotalVal + creditVal
sInsData = "update Bank  set Credit = " & creditVal & " where account=" & userAcctNo
MyConn.Execute(sInsData)
sInsData = "update Bank  set Total = " & totalVal & " where account=" & userAcctNo
MyConn.Execute(sInsData)
msgbox "Credited Successfully"

end function


'function to update date to the account entered
function changeAddr

userAcctNo = Inputbox ("Enter the Account number")
call getAmtVals
'validating account exists or not
if user_exists=false  then
msgbox "Account not found"
exit function
end if

address=Inputbox ("Enter the new address value")
sInsData = "update Bank  set address = '" & address & "'" & " where account=" & userAcctNo
MyConn.Execute(sInsData)
msgbox "Address Updated Successfully"

end function


'function to add new entry
function newEntry

hName=Inputbox ("Enter the Account Holder Name")
hAccount=Inputbox ("Enter the Account number")
hAddress=Inputbox ("Enter the Address")
sql = "insert into Bank(HName,Account,address,debit,credit,total) values('" & hName & "',"& hAccount & ",'" & hAddress & "',0,0,0);"
MyConn.Execute(sql)
msgbox "User Added Successfully!!!!"
end function

Example Student table: Update Query in VBScript



''================================================================= 
            Create a new table in MS Access called Student and perform given task.

        Student Table Structure
           1.       RollNo
           2.       Name
           3.       Address
           4.       Subject
           5.       Mark1
           6.       Mark2
           7.       Mark3
           8.       Avg Marks
           9.       Total

Write a script to perform below task:
1.       Function to calculate Avg Marks of all subjects and update in Avg Marks column.(for all subject)
2.       Function to calculate total marks and update in the total column.
3.       Function to update the address of particular student ( Take input from user)
''================================================================= 


Dim a,b,Avg, TOtal,Address
f = False

Call Avg_Marks

Function Avg_Marks
Set a=CreateObject("adodb.connection")
a.Open "Data Source=E:\Student.mdb;Provider=Microsoft.jet.oledb.4.0"
Set b=a.Execute("select * from student ")
RNo=Cint(inputbox("Enter the RollNo"))

WHILE NOT b.EOF
count = count + 1
if RNo = b("RollNo") then
sm1 = b("Mark1")
sm2 = b("Mark2")
sm3 = b("Mark3")
msgbox "Roll No:" & RNo & " sm1:" &sm1 & " sm2:" &sm2 & " sm3:" &sm3

end if
b.MoveNext
    WEND
if Rno > count then
msgbox "record no found"
else
Avg=(sm1+sm2+sm3)/3
Msgbox "Avg:" & Avg
sql="update student set AvgMarks="&Avg&" where RollNo =" & RNo
'msgbox sql
a.Execute (sql)
Call Total_Marks(RNo,sm1,sm2,sm3,Avg)
end if
End Function

Function Total_Marks(RNo,sm1,sm2,sm3,Avg)
Total=sm1+sm2+sm3
msgbox "Total:" & Total
sql="update student set Total="&Total&" where RollNo="&RNo
'msgbox sql
a.Execute (sql)
Call Address_value(RNo,sm1,sm2,sm3,Avg,Total)
End Function

Function Address_Value(RNo,sm1,sm2,sm3,Avg,Total)
    Address=inputbox("Enter the address")
  msgbox "Address:" & Address
  sql="update student set AvgMarks="&Avg&",Total="&Total&",Address='"&Address&"' where RollNo="&RNo
msgbox sql
a.Execute (sql)
a.Close
End Function

Example of ADODB.Connection and ADODB.Recordset in VBscript


    Set MyConn = CreateObject("ADODB.Connection")
    MdbFilePath = "C:\Users\ladn\Desktop\Neeraj.mdb"
    MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"

 
    SQL_query = "SELECT * from Student"
 
     set rs=CreateObject("ADODB.recordset")
     rs.Open SQL_query, MyConn
 
    count = 0
    WHILE NOT RS.EOF
count = count + 1
name = rs("name")
add = rs("address")
msgbox name & add
       rs.MoveNext
    WEND
msgbox count
    rs.Close
    set rs = nothing
    MyConn.close
    set MyConn = nothing

ODBC Connection for MS Access



  • Click on Start button
  • Select Control Panal
  • Click on Administrator Tools
  • Click on Data Sources (ODBC)
  • ODBC Data Source Administrator window will open as below screenshot



  • To Add MS Access User Data Source, Click on Add button
  • Create New Data Source window will open


  • Select “Diver do Microsoft Access (*.mdb)”  from Create New Data Source window and click on finish button.
  • ODBC Microsoft Access Setup Window will open


  • Write Data Source Name and Description if need,
  • Click on Select button  and select mdb file from the location (see below screenshot)


  • Click on OK button after selecting mdb file


  • Database will display under ODBC Microsoft Access Setup window and click on OK button


  • MS Access User DSN Will display MS Access Driver name.



Friday, June 15, 2012

Reverse String without using any String function


Dim str1,regExpObj,x,result
Dim ArrString
str1="Neeraj"

Set regExpObj = new regexp
regExpObj.pattern="[a-z A-Z]"
regExpObj.global=true
set ArrString=regExpObj.execute(str1)
For each x in ArrString
result = x.value & result
Next
msgbox result

Search entered text from inside of the text file.



set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.OpenTextFile("Path_of_the_text_file.txt",1, False)
val=Inputbox("enter the word to be searched")
flag = false
do until f.AtEndOfStream
str1=f.readLine
if inStr(str1,val) then
flag = True
exit do
else
flag = false
End if
Loop
if flag = True then
msgbox val & " found"
else
Msgbox val & " not Found"
f.close
set f=nothing
set fso=nothing

Thursday, June 14, 2012

Find no is Prime or not from range in vbscript



Function primeNumber()
flag=1
primeNo=inputbox("Enter a number")
For n=2 to primeNo
flag=1
For j=2 to n/2
If n mod j=0 Then
flag=0
End If
Next
If flag=1 Then
msgbox "prime no is:" & n
End If
Next
End Function