RSS
 

Archive for May, 2010

#7: Relationship among VBScript, Visual Basic for Applications (VBA), Visual Basic (VB), Visual Basic .NET, and JavaScript

28 May

QTP uses the Visual Basic Scripting Edition (VBScript) scripting language, TestPartner is based on the Visual Basic for Applications (VBA), and RFT’s test script is produced as either a Java or Visual Basic.net application.

VBScript is a subset of the Visual Basic Programming language. The result of the slimming down process is a very small language that is easy to use. JavaScript can do all that VBScript can do and far more. So why use VBScript instead of JavaScript? Because VBScript is much easier to learn than JavaScript.

Visual Basic for Applications (VBA) is another subset of the Visual Basic Programming language for use with Microsoft Word, Excel, Access etc. While it contains a good many features not supported by VBScript, the basic syntax, or construction of the language, is very similar.

RFT is not the main focus for this blog, at least not yet, so for Java vs. VB.NET, you only need to know that Java is programming environment controlled by Sun, and VB.NET is developed by Microsoft.

As said above, both VBScript and VBA are subsets of Visual Basic (VB). The final release of VB was version 6 in 1998. Microsoft’s extended support ended in March 2008 and the designated successor was Visual Basic .NET (now known simply as Visual Basic)

After learning the history of the VB family and JavaScript, let us play a small game by writing the VBScript in a notepad. This is very useful if you do not want to bother to repeat the same thing over and over again.

Copy the following code into a notepad, and save it as kk.vbs, then double click on it, and see what it will do.

Dim fs, file, TSTnumber
set fs = createobject( "Scripting.FileSystemObject" )
set file = fs.OpenTextFile( "RF.BAT", 2, true )

For TSTnumber=613 to 616
file.write "VsiColorModeRAW.exe tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.bmode tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.color tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.xml tst-18-0"
file.write TSTnumber
file.writeline "\Color"
Next
file.close
set fs=nothing
 

#6: Use QTP to test miscellaneous log in functions for YouPlayOff.com

25 May

In this blog, I will show you how to use QTP to test YouPlayOff.com for the following functions:
1, log in as a confirmed user, the “Add New” player link exists
2, Log in as non-confirmed user, the “Add New” player link won’t exists
3, Log in from log out page, the page will c to Home page

From this blog, you should be able to practice and learn the following:
1, How to define an object (i.e., not a number, not a string, etc.) (Dim and Set);
2, How to check if an object exists (object.exist);
3, How to write test result directly to the test result summary (Reporter.ReportEvent);
4, How to use If Then;

Dim addLink, addLinkText
addLinkText = "Add New"

'Confirmed user: addLink exists
Browser("YouPlayoff - Create and").Page("YouPlayoff - Create and").Sync
Browser("YouPlayoff - Create and").Navigate "http://testing.youplayoff.com/category/28/Hockey/?type=1"
Browser("YouPlayoff - Create and").Page("YouPlayoff - Hockey Players_2").Link("Sign In").Click
RunAction "Log in [Log in]", oneIteration

Set addLink = Browser("YouPlayoff - Create and").Page("YouPlayoff - Hockey Players").Link("text:=" & addLinkText)
If addLink.Exist Then
 Reporter.ReportEvent micPass, "Find the AddNew Link when logged in as confirmed user", "PASS"
Else
 Reporter.ReportEvent micFail, "Can NOT find the AddNew Link when logged in as confirmed user", "FAIL"
End If

'Check redirect function of login from logout page
Browser("YouPlayoff - Create and").Page("YouPlayoff - Hockey Players_3").Link("Sign out").Click
Browser("YouPlayoff - Create and").Page("Logout - YouPlayoff").Link("Sign In").Click
Browser("YouPlayoff - Create and").Page("Login - YouPlayoff").WebEdit("name").Set "guidebillion"
Browser("YouPlayoff - Create and").Page("Login - YouPlayoff").WebEdit("password").SetSecure "4c09bae5a2cf4dc2f458b8815ed6e83fdd06dd004f8f346d"
Browser("YouPlayoff - Create and").Page("Login - YouPlayoff").WebButton("Submit").Click
Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("Edit")

'Non-confirmed user: addLink does not exist
Browser("YouPlayoff - Create and").Navigate "http://testing.youplayoff.com/category/28/Hockey/?type=1"

Set addLink = Browser("YouPlayoff - Create and").Page("YouPlayoff - Hockey Players").Link("text:=" & addLinkText)
If addLink.Exist Then
 Reporter.ReportEvent micFail, "Find the AddNew Link when logged in as NON-confirmed user", "FAIL"
Else
  Reporter.ReportEvent micPass, "Can NOT find the AddNew Link when logged in as NON-confirmed user", "PASS"
End If

Browser("YouPlayoff - Create and").Page("YouPlayoff - Hockey Players").Link("Sign out").Click
Browser("YouPlayoff - Create and").Page("Logout - YouPlayoff").Link("Home").Click
 

#5: Use QTP to test Log in page redirect function for YouPlayOff.com

17 May

In this blog, let’s test the log in redirect function, i.e., from page A, choose log in, then the borrower should be redirected to page A.

This test is complicated, since I want to test multiple starting pages in one action. I would suggest you to try this first by yourself, and I am pretty sure you will have questions, then you can come back to read this blog and solve your questions one by one.

What scripting skills you can practice or learn from this test:
1, Call an existing action (RunAction);
2, Use the DataTable to test multiple inputs;
3, Difference between Global DataTable and Local DataTable (run multiple iterations);
4, How to define variables (Dim);
5, How to wait until certain page is loaded (Sync);
6, How to navigate to a web-page (Navigate);
7, How to handle URLs which contain question mark (?);
8, How to find certain character is in the string (InStr);
9, How to replace characters in a string (Replace);
10, How to use message box (msgBox);
11, How to identify an object from different pages dynamically (Page(“url:=” & PageURL).Link(“text:=” & SignInText));
12, How to use Select Case;
13, How to add comment in the Expert View (‘);
14, How to add a Checkpoint;
15, How to check according to the value from a DataTabel;
16, In order to start next iteration successfully, you need to reset the test environment at the end of the test.

'Page redirect fuction after log in
Dim PageURL
Dim SignInText
Dim SignOutText
PageURL = DataTable("A", dtGlobalSheet)
SignInText = "Sign In"
SignOutText = "Sign Out"

'Wait till the home page is open, this may take a while
Browser("YouPlayoff - Create and").Page("YouPlayoff - Create and").Sync

'Navigate to the URLs listed in the Data Table
Browser("YouPlayoff - Create and").Navigate PageURL

'When URL contains question mark needs special handle
'If InStr (PageURL, "?") <> 0 Then
 PageURL = Replace (PageURL, "?", "\?")
'End If
'msgBox (PageURL)

'From the page opened above, click the "Sign In" link
Browser("YouPlayoff - Create and").Page("url:=" & PageURL).Link("text:=" & SignInText).Click

'Call an existing action for log in only.
RunAction "Log in [Log in]", oneIteration

Select Case PageURL

'In the VBScript, Page("url:=" & "http://testing.youplayoff.com") can not be written as Page("url:=" & "http://testing.youplayoff.com/")
'As a result, in the data table, the data has to be stored as "http://testing.youplayoff.com" instead of "http://testing.youplayoff.com/"
'However, the real URL is "http://testing.youplayoff.com/" instead of "http://testing.youplayoff.com", so this case can not be checked by using the data table.
'After checking, log off
Case  "http://testing.youplayoff.com"
 Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("redirecttohomepage")
 Browser("YouPlayoff - Create and").Page("url:=http://testing.youplayoff.com").Link("text:=" & SignOutText).Click

'Login from register page, the home page will open
'After checking, log off
Case  "http://testing.youplayoff.com/register"
   Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("redirecttohomepage")
   Browser("YouPlayoff - Create and").Page("url:=http://testing.youplayoff.com").Link("text:=" & SignOutText).Click

'Login fromlogin page, the home page will open
'After checking, log off
Case  "http://testing.youplayoff.com/Login"
   Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("redirecttohomepage")
   Browser("YouPlayoff - Create and").Page("url:=http://testing.youplayoff.com").Link("text:=" & SignOutText).Click

'Login from logoutpage is tested in another test called "Log in as nonconfirmed user, redirect from logout page"

'Login from create page, the select-category  page will open (select-category is first step of create a playoff, but this step is only visible to logged in user)
'After checking, log off
Case  "http://testing.youplayoff.com/create"
 Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("RedirectAfterCreate")
 Browser("YouPlayoff - Create and").Page("url:=http://testing.youplayoff.com/create/playoff/select-category").Link("text:=" & SignOutText).Click

'Redirect to previous page after login, so use the data table to check
'After checking, log off
Case Else
 Browser("YouPlayoff - Create and").WinEdit("Edit").Check CheckPoint("RedirectToPreviousPage")
 Browser("YouPlayoff - Create and").Page("url:=" & PageURL).Link("text:=" & SignOutText).Click

End Select 

'Navigate back to home page
Browser("YouPlayoff - Create and").Navigate "http://testing.youplayoff.com/"

Global Data Table: (you can also read the data from an Excel file directly, see post#9)

http://testing.youplayoff.com

http://testing.youplayoff.com/register

http://testing.youplayoff.com/Login

http://testing.youplayoff.com/create

http://testing.youplayoff.com/categories

http://testing.youplayoff.com/categories/tree

http://testing.youplayoff.com/categories/popular

http://testing.youplayoff.com/playoffs

http://testing.youplayoff.com/recommended

http://testing.youplayoff.com/recent

http://testing.youplayoff.com/groups

http://testing.youplayoff.com/whatsup

http://testing.youplayoff.com/whatsup?show=2

http://testing.youplayoff.com/whatsup?show=3

http://testing.youplayoff.com/help

http://testing.youplayoff.com/about

http://testing.youplayoff.com/privacy

http://testing.youplayoff.com/terms

http://testing.youplayoff.com/contact