Sunday

C# - Database connection (SQLSERVER) by c sharp function

DBConnect();

using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;


protected void DBConnect()
{



System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = "Data Source=THOKR02-XP;Initial Catalog=OnDemand;Integrated Security=True";
conn.Open();

SqlCommand command = new SqlCommand("SELECT [TestSuite_Name] FROM [OnDemand].[dbo].[TestSuites]", conn);
SqlDataReader reader = command.ExecuteReader();
DropDownList1.Items.Clear();
while (reader.Read())
{

//TextBox2.Text = (String)reader[0];
DropDownList1.Items.Add((String)reader[0]);
}
reader.Close();
conn.Close();

}

Friday

STAF - Installation on Linux Machine

STAF - Installation on Linux Machine

STEP 1: Software Installation
All the required software are
1. apache-tomcat-6.0.20.tar.gz
2. jre-6u16-linux-i586.bin
3. STAF335-linux.tar.gz


Software: STAF335-linux.tar.gz
Unzip and untar it at the location where you want to install:
gunzip –d STAF335-linux.tar.gz
tar xvf STAF335-linux.tar

Now, navigate to Staf directory and run below command
./STAFInst –acceptlincense -acceptlicense

Once you run the above command, files will get generated in the Staf home directory (By default it will be /usr/local/staf).
Make sure that STAFEnv.sh and startSTAFProc.sh files got created.
Note: If you do not get these files, you cannot move on with the installation.

Now run the below command from the Staf home directory.
chmod a+x STAFEnv.sh
. ./STAFEnv

Now run the below command from the Staf home directory.
chmod a+x startSTAFProc.sh
./startSTAFProc.sh
You should get “nohup: appending output to `nohup.out'” as response.

Verification:
Type STAF local PING PING
PONG should be your response.

NOTE: To let other machines to ping your machine, give the trust level to other machines in “staf .cfg” file.
Find the sample staf .cfg file attached.

# Turn on tracing of internal errors and deprecated options
trace enable tracepoints "error deprecated"

# Enable TCP/IP connections
#interface ssl library STAFTCP option Secure=Yes option Port=6550
interface tcp library STAFTCP option Secure=No option Port=6500

# Set default local trust
trust machine local://local level 5


# Add default service loader
serviceloader library STAFDSLS

TRUST LEVEL 5 MACHINE tcp://machinename-xp.in.com

Once you are done with above step, run the below command
./etc/init.d/iptables stop
The above command will let other machines to connect to your machine without any problem


" you can ping now windows and linux machine added in trusted list"

Thursday

Web devlopment .aspx page creation.

1. Install VS WebDevloper Express from Microsoft

2. OPen VS and select new project with .asp extension

3. Connect database by Go in Design Panel
Database Explorer
Connect to Database ( any kind)
4. big the DIV tag panel (for object Accomodation)
5. Create a drop down to get value of colum in table
add Dropdown list from the Standar (toolbox ) inleft Panel

Click on newly added Object and Select Data source
Click on databases

check the connect string like Data Source=THOKR02-XP;Initial Catalog=OnDemand;Integrated Security=True
The specify Query

chose Where clause and Source is Control (actualy that Object)
Click on advance " Generate Insert update Delete
Go in Design Panel
Select Form View

Edit template




Go in Design Panel
Select Validation ( like see not more than 15 Char)
Select Required field and drag and drop agains the row in form where we want to validate.


Now run sample Application ....
see ASP.NET Devlopment Server runs ASP.NET application locally Dilaoge box ...
gives URL
Port : 1749
Virtual Path : /WebSite1
and Physical Path: C:\My Documents\Visual Studio 2008\WebSites\WebSite1\

Tuesday

On demand Testing Framework - Keyword Driven

What this program will do : it will read the Yes flag and then run the QTP on the particular machine. Which is given into the column "Where want to Run PATH - QC or any other Path"
Prerequisite: Might be DCOM setting need to do for remote execution.

Run prompt > dcomcnfg > Component service > Computer > My computer > DCOM config > right click on QuickTest Professional Automation > security > add the name of user for alll three customize radio button from which you want to run the QTP scripts.

Steps:
Design the Exel with coulmn
Testcasename Where want to Run PATH - QC or any other Path Run On demand When You want to run AM/PM Enviorment URL Resultant Command TSR Location USER


Sample:

Testcasename Where want to Run PATH - QC or any other Path Run On demand When You want to run AM/PM Enviorment URL Resultant Command TSR Location USER
TC_Login shukr02-xp YES Now PM www.Build1.com C:\Automation\TestSuite
TC_CreatRequest Load Sharing Machine NO Now AM www.Build1.com C:\Automation\TestSuite
TC_AmendRequest Load Sharing Machine NO Now PM www.Build3.com C:\Automation\TestSuite
TC_DO_Question Load Sharing Machine NO Now AM www.Build4.com C:\Automation\TestSuite
TC_PutRecommendation Load Sharing Machines NO Now AM www.Build1.com C:\Automation\TestSuite
TC_LogIncident Load Sharing Machine NO Now AM www.Build1.com C:\Automation\TestSuite
TC_resubmit Incident Load Sharing Machine NO 10:20 AM www.Build2.com C:\Automation\TestSuite
TC_SendEmail Subject\QTPFolder\Automation Suite NO 10:34 PM www.Build2.com C:\Automation\TestSuite
TC_LogtheBug0 alara01-xp YES Now AM www.Build2.com \\alara01-xp\Automation\TestSuite
TC_LogtheBug1 alara01-xp NO Now AM www.Build2.com \\alara01-xp\Automation\TestSuite
TC_LogtheBug Load Sharing Machines NO Now AM www.Build2.com C:\Automation\TestSuite
EOF EOF EOF EOF EOF EOF EOF EOF EOF



Select Task
QTP Automation YES
CURL Automation - Sheet 2 NO
Build Deployment - Sheet 3 NO


Macro to run this Code:

'OnDEmandAutomation ("C:\AutomationTesting\TestSuite.xlsm")
Sub OnDEmandAutomation()

'Shell Environ$("COMSPEC") & " /k C:\AutomationTesting\StartAutomation.bat"

Dim tNum, tLoc(100), tCase(100), tTime(100), tTimeAMPM(100), tEnv(100), tpth(100)
APath = "C:\AutomationTesting\TestSuite.xlsm"
tNum = 0

Dim rowCount
rowCount = 2

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
xlApp.Workbooks.Open APath

'xlApp.ScreenUpdating = False
'Set objSheet=xlApp.Workbooks(APath).worksheet("Sheet1")
Set objSheet = xlApp.ActiveWorkbook.Worksheets(1) ' Take Active WorkBook




screenRow = 0

For rowNumber = 2 To 100

screenRow = screenRow + 1

If objSheet.Cells(rowNumber, 1) = "EOF" Then
Exit For

Else
If objSheet.Cells(rowNumber, 3) = "YES" Or objSheet.Cells(rowNumber, 1) = "EOF" Then
tCase(tNum) = objSheet.Cells(rowNumber, 1).Value
tLoc(tNum) = objSheet.Cells(rowNumber, 2).Value
tTime(tNum) = objSheet.Cells(rowNumber, 4).Value
tTimeAMPM(tNum) = objSheet.Cells(rowNumber, 5).Value
tEnv(tNum) = objSheet.Cells(rowNumber, 6).Value
tpth(tNum) = objSheet.Cells(rowNumber, 7).Value


For rt = 0 To 0

'sComp = tLoc(tNum)
'Set WMIobj = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
'Set IEExp = WMIobj.ExecQuery("Select * from Win32_Process Where Name = 'QTPro.exe'")
'MsgBox IEExp.Count
'For Each IEx In IEExp
' IEx.Terminate()
'Next
'Set WMIobj = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
' Find All the iexplore.exe processes
'Set IEExp = WMIobj.ExecQuery("Select * from Win32_Process Where Name = 'iexplore.exe'")
'For Each IEx In IEExp
' IEx.Terminate()
'Next

'Shell Environ$("COMSPEC") & " /k C:\AutomationTesting\LaunchQTP.bat"
'wscript.exe "C:\AutomationTesting\Testrun.vbs"
'If tLoc(tNum) <> "shukr02-xp" Then
'staf_command(tNum)="Staf" & tLoc(tNum) & "process start command" QTPro.exe
Set qtApp = CreateObject("QuickTest.Application", tLoc(tNum)) ' tLoc(tNum) Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' ' Make the QuickTest application visible
qtApp.Open tpth(tNum), False
qtApp.Test.Run
'qtApp.Test.Close ' Close the test
qtApp.Quit
Set qtApp = Nothing

'Else
'staf_command(tNum)="Staf" & tLoc(tNum) & "process start command" QTPro.exe
'Set qtApp1 = CreateObject("QuickTest.Application") ' Create the Application object
'qtApp1.Launch ' Start QuickTest
'qtApp1.Visible = True ' ' Make the QuickTest application visible
'qtApp1.Open tpth(tNum), False
'qtApp1.Test.Run
'qtApp.Test.Close ' Close the test
'qtApp1.Quit
'Set qtApp1 = Nothing
'End If



Next


'qtApp.Quit ' Exit QuickTest

'Set qtApp = Nothing ' Release the Application object

tNum = tNum + 1


'tNum = tNum + 1
'msgBox "Testcase" & testCase
End If
End If
Next

xlApp.Quit

KillProcessEXCEL = "EXCEL.EXE"
Set ProcessList2 = GetObject("winmgmts://.").InstancesOf("win32_process")
For Each Process In ProcessList2
If Process.Name = KillProcessEXCEL Then
Process.Terminate
End If
Next

'Call AttachHTMLAsMailContent("Team-Picasso-QA123", "shukr02", "alara01", "Automation Completed", "http://result.com")

End Sub


'Function AttachHTMLAsMailContent(sSendTo, sSendToCC, sSendToBCC, sSubject, sHtmlPath)

'Dim objOutlook
'Dim objOutlookMsg
'Dim olMailItem

' Create the Outlook object and the new mail object.
'Set objOutlook = CreateObject(Outlook.Application)
'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

' Define mail recipients
'objOutlookMsg.To = sSendTo
'objOutlookMsg.CC = sSendToCC
'objOutlookMsg.BCC = sSendToBCC

' Body of the message

'With objOutlookMsg
'Set fso = CreateObject(Scripting.FileSystemObject)
'Set ts = fso.OpenTextFile(sHtmlPath, 1)
'strText = ts.ReadAll
'.HTMLBody = strText
'.Display
'End With

' Send the message
'objOutlookMsg.Send
'Wait (3)

' Release the objects
'Set objOutlook = Nothing
'Set objOutlookMsg = Nothing

'End Function

QTP - Reading Command prompt from QTP

'Add the command prompt as a object in QTP OR.

myname=SysExecute("dir")
MsgBox myname

Function SysExecute(ByVal strCmdtoExecute)
Dim Output ' Variant
SystemUtil.CloseProcessByName("cmd.exe")
Wait 2
SystemUtil.Run "cmd", "/K cd c:\ & cls", "", "", 1
Wait 3
sPrompt = window("CommandWindow").GetVisibleText

if(sPrompt <> " ") then
myarray = split(sPrompt,vbCRLF)
if(ubound(myarray)>0) Then
lastline = ubound(myarray)
sPrompt = myarray(lastline)
else
sPrompt = "c:\>"
end if
else
sPrompt = "c:\>"
end if

with window("CommandWindow")
.activate
.type strCmdtoExecute
.type micreturn
end with
i=1
Do While True
cmdOutput = window("CommandWindow").GetVisibleText
myarray = split(cmdOutput,vbCRLF)
if(ubound(myarray)>0) Then
lastline = ubound(myarray)
sNewPrompt = myarray(lastline)
if(StrComp(sPrompt,sNewPrompt,0) = 0) then
For j = 1 to lastline -1
Output = Output & vbcrlf & myarray(j)
Next
Exit do
end if
else
lastline = ubound(myarray)
end if
if(i>15) then 'Exit condition
if(lastline > 3) then
For j = 2 to lastline -1
Output = Output & vbcrlf & myarray(j)
Next
else
Output = " "
end if
Exit do
end if
i=i+1
Loop

SysExecute = Output
window("CommandWindow").Close
Wait 2
Exit function
End Function

Monday

QTP - Matching pattern in string by regular expression

MsgBox(RegExpTest("ab","abhishek"))

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
'If want to search multiple lines
'MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

Friday

STAF - Software Test Automation Framework

Installation and setting machine:

STEP;1 : INstall STF in C:\STAF
Step2: create C:\STAF\service folder
Step3: put Stax in the service folder
STEP 4: Install perl and Python
STEP 5:Set classpath add -->C:\STAF\bin\JSTAF.jar;C:\python22\lib;
classpath add -->C:\STAF\bin\JSTAF.jar;C:\python22\lib;C:\perl\lib;
path add -->C:\STAF\bin;C:\Python22;c:\perl\bin;
create a new variable with PYTHONPATH and set the value C:\STAF\bin;
create a new variable STAF_DIR with the value c:\staf;
STEP 6:OPen the staf.cnf file from c:\staf\bin. put line given below
SERVICE STAX LIBRARY JSTAF EXECUTE C:\STAF\services\stax\STAX.jar
SERVICE EVENT LIBRARY JSTAF EXECUTE C:\STAF\services\stax\STAFEvent.jar
Step 7: Set trust level
TRUST LEVEL 5 MACHINE shukr02-RH5
Step 8: comment the line SSL in staf.cnf file

Step9: set the other trust machine.

Step 10: start Staf


Command:
Go to C:\staf folder in command prompt:
1.To Open the commad promt on trusted machine
staf process start process cmd.exe
staf process start process cmd.exe

2. Copy the file from one locatoin to other location:
C:\>STAF local FS COPY FILE "C:\Program Files\file1.txt" TOFILE "C:\Program Files\file2.txt"
STAF local PROCESS START SHELL COMMAND "copy \"C:\Program Files\file1.txt\" \"C:\Program Files\file2.txt\"" WAIT RETURNSTDOUT STDERRTOSTDOUT

3.LIST DIRECTORY ( like ls in Unix)
STAF local FS LIST DIRECTORY "C:\Program Files"
4.More kind of Unix command facility
like more "C:\Program Files\file1.txt"
STAF local PROCESS START SHELL COMMAND "more \"C:\Program Files\file1.txt\"" WAIT RETURNSTDOUT STDERRTOSTDOUT SAMECONSOLE
STAF local FS GET FILE "C:\Program Files\file1.txt"
5.echo this is the string to be parsed > "C:\Program Files\echofile.txt"

if fiile will not there it will craete the file:

this command will replace the content of file and put the string given after echo "this is the string to be parsed "

STAF local PROCESS START SHELL COMMAND "echo this is the string to be parsed > \"C:\Program Filesr\echofile.txt\"" WAIT RETURNSTDOUT STDERRTOSTDOUT