Thursday, 18 July 2019

UFT:'ReadParameter_FN

'@Description This function reads the action parameter value and returns back.
'@Documentation This function reads the action parameter value and returns back.
Function ReadParameter_FN(str_Name)

Err.Clear
Dim tempValue
tempValue = str_Name
On Error Resume Next

dataSource = "Global"
ReadParameter_FN = Datatable.Value(str_Name,dataSource)

If Err.Number <> 0 Then
Err.Clear
dataSource = Environment.Value("ActionName")
If Environment.Value("localRowIndex") = 0 Then
Environment.Value("localRowIndex") = 1
End If
datatable.LocalSheet.SetCurrentRow Environment.Value("localRowIndex")
ReadParameter_FN = Datatable.Value(str_Name,dataSource)
End If


If Err.Number <> 0 Then
Call ReportEvent_FN("Fail", "Read Value from Datasheet", "Reading parameter : "&str_Name&" from Datasheet is failed. Description:"&Err.Description)
End If

Err.Clear

End Function

UFT: WriteParameter_FN

'@Description This function writes the action parameter value and returns back.
'@Documentation This function writes the action parameter value and returns back.
Function WriteParameter_FN(str_Name, str_Value)

Err.Clear
     On Error Resume Next
Datatable.Value(str_Name,dataSource) = str_Value

If Err.Number <> 0 Then
DataTable.getSheet(dataSource).AddParameter str_Name, str_Value
Err.Clear
End If

If dataSource <> "Global" Then
Datatable.Value(str_Name,"Global") = str_Value
If Err.Number <> 0 Then
DataTable.getSheet("Global").AddParameter str_Name, str_Value
Err.Clear
End If
End If
Err.Clear

End Function

UFT ValidateRegularPattern_FN function

Function ValidateRegularPattern_FN(str_Pattern, str_Value)
Err.Clear

Dim regEx, Match

Set regEx = New RegExp   ' Create a regular expression.
regEx.Pattern = str_Pattern   ' Set pattern.
regEx.IgnoreCase = True   ' Set case insensitivity.
regEx.Global = True   ' Set global applicability.
Match  = regEx.Test(str_Value)   ' Execute search.
 
ValidateRegularPattern_FN = Match

Err.Clear

End Function

Saturday, 25 May 2019

UFT: Using Class File in UFT Action

'###CLASS FILE

ExecuteGlobal "Dim Reporter"
Set Reporter = New HtmlReporter


Class HtmlReporter
 
Public Sub Class_Initialize(  )
   
    print "started"
   
    Systemutil.CloseProcessByName "iexplore.exe"
    Systemutil.Run "iexplore.exe"
End Sub
   
'When Object is Set to Nothing
public Sub Class_Terminate(  )
       
    Systemutil.CloseProcessByName "iexplore.exe"
   
    print "ended"
End Sub
   
End Class



'###ACTION


msgbox datatable.Value("Value")


'#DATATABLE
Value
1
2
3

Saturday, 11 May 2019

ADODB my SQL Connection with VbScript

Function test()

On Error Resume Next

Set obj = CreateObject("ADODB.Connection")
Set obj1 = CreateObject("ADODB.RecordSet")
Dim dbquery
dbquery = "INSERT INTO test (firstname,lastname) VALUES ('neha','deshmukh');"

obj.Open "Server=db4free.net;Data Source=mysql; Database=sumit1234; User=sumit1234; Password=sumit1234;"

MsgBox obj1.State & ""

MsgBox Err.Description
obj1.Open dbquery, obj

MsgBox Err.Description

obj.Close
obj1.Close
Set obj1 = Nothing
Set obj = Nothing


End Function

Thursday, 9 May 2019

JDBC: My Sql Insert Statement

package mysqlconnect;

import java.sql.*; 
class Insert{ 
public static void main(String args[]) throws SQLException, ClassNotFoundException{ 
   
Class.forName("com.mysql.jdbc.Driver"); 
Connection con=DriverManager.getConnection( 
"jdbc:mysql://db4fre.net/sumit1234","sumit1234","sumit1234"); 
//here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password 
Statement stmt=con.createStatement(); 
String begin = "INSERT INTO `test`(`firstname`, `lastname`) VALUES ";

for (int i = 2000; i < 3001; i++) {

begin = begin + "(" + i + "," + (i + 10) + ")" + ",";
}

begin = begin.replaceAll(",$", ";"); //As we want ; after last value
stmt.executeUpdate(begin); //INSERT DELTE UPDATE needs executeUpdate
   
con.close(); 



}

JDBC: Mysql Select Statement

package mysqlconnect;

import java.sql.*;
class TestConnection{
public static void main(String args[]){

try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://db4fr.net/sumit1234","sumit1234","sumit1234");

// here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password

Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from test");
while(rs.next())

System.out.println(rs.getString(1)+"  "+rs.getString(2));  //BE CAREFUL HERE . DIFFERENT FIELDS HAVE DIFFERENT datatype
//System.out.println("reached inside while");

con.close();  //Closing Connection

}catch(Exception e){ System.out.println(e);}
}
}



'################OUTPUT##################################################

sumit  raut
1  11
2  12
3  13
4  14
5  15
6  16
7  17
8  18
9  19
1  11
2  12
3  13
4  14
5  15
6  16
7  17
8  18
9  19
2000  2010
2001  2011
2002  2012
2003  2013
2004  2014
2005  2015
2006  2016
2007  2017


Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...