Sunday 24 September 2017

TestComplete - Name Mapping

Name Mapping -

NameMapping is a collection of objects, where we can stored the object information by specifying objects properties and their particular values that the TestComplete engine will use for the object identification and perform the actions on it.

We have multiple option in TestComplete to add (stored) the objects in NameMapping-

1- Recording Test :- When a user records a test, the objects and its properties are stored by default in NameMapping.



2- Object Spy: - Object Spy is a inbuilt feature in TestComplete to identify the objects information and  add into the NameMapping.

To Add the Objects from Object Spy to NameMapping -> Show the object to Object spy -> Right Click the Object in Object Spy and select Map Object from the context menu.

(To Open Object Spy:1- Select Tools|Display Object Spy OR Toolbar option)


3- Object Browser :- The Object Browser shows running applications, the hierarchy of objects in applications, and object properties and methods.

To Add the Objects from Object Browser to NameMapping ->Right-click the object in the Object Browser and select Map Object from the context menu.

(To Open Object Browser : 1- Select View | Object Browser OR Click on Object Browser tab)




To be Continued .....

(Upcoming blogs :- NameMapping feature and use of NameMapping)


Wednesday 6 September 2017

How to Load/Activate NameMapping at run time in TestComplete

Suppose In your project, If you have multiple Name Mapping Configuration or Multiple Name Mapping File (repository) and you wanted to load/activate any specific Name Mapping configuration at run time, then yes TestComplete allow us to do this.

To Load/Activate the specific Name Mapping configuration at run time

          NameMapping.CurrentConfigurationName = "My_NM_Config_Name"

To know the current loaded/Activated NameMapping configuration at run time-

          My_NM_Config_Name = NameMapping.CurrentConfigurationName


For get the count of NameMapping configuration at run time

          My_NM_Config_Count = NameMapping.CurrentConfigurationCount

We can determine the Number of NameMapping configurations , name by using Index at run time

          My_NM_Config_Name = NameMapping.ConfigurationNames(0)

Note - NameMapping.ConfigurationNames(Index) Specifies the index of the desired NameMapping configuration. The index is zero-based.



Friday 25 August 2017

XPath in TestComplete

XPath is one of the most important and powerful feature for web automation testing.
When TestComplete not able to found the web elements using object spy or descriptive programming then We can use the XPath for searching the location of any web elements on web page, XPath using the HTML DOM structure to searching web elements.

TestComplete provides the two important methods for searching the web elements by their attributes.We can use various XPath expressions in TestComplete methods.

1- FindChildByXPath()
2- EvaluateXPath()

1- FindChildByXPath(): - This function searches all the web elements (objects), which are matches the search condition (XPath Expressions) This function apply the searching on visible or non visible web page objects.This function return a Single object.

If the search condition (XPath Expressions) failed than it returns a NULL Object or in case if multiple objects match the search condition than it returns first found element as a object.

Syntax:-

     TestObj.FindChildByXPath(XPath, True/False)

Example 1 :- Single Object

Set ObjTextBox = Sys.Browser.Page("http://google.com/").FindChildByXpath("//input[@name='q']",Treu)


here 1 match found with the xpath expression hence FindChildByXpath() return a object for google search box.






 Example 2 :- Multiple Objects

Set ObjTextBox = Sys.Browser.Page("http://google.com/").FindChildByXpath("//*[contains(@name,'btn')]",Treu)


here multiple objects matched the xpath expression hence FindChildByXpath() return the object for Google Search button.



















2- EvaluateXPath(): - This function searches all the web elements (objects), which are matches the search condition (XPath Expressions) This function apply the searching on visible or non visible web page objects.This function return an Array of found objects.

If only one object found in search condition (XPath Expressions) than its returns an array that contains one item.If there is no object found than its return array item contains the appropriate HTML object.

Syntax :-

          TestObj.EvaluateXPath(XPath, True/False) 

Example :-

testObj = Sys.Browser.Page("http://google.com/").EvaluateXPath("//*[contains(@name,'btn')]",Treu)


Note: - FindChildByXPath return a single found object &  EvaluateXPath return an Array of found objects.

Saturday 26 December 2015

Project & Project Suite Variable in TestComplete

Project & Project Suite variables are special type of variables in TestComplete that can be accessed by all TestUnit (Script unit) , Keyword Test, Network Suite and Events. These are the global variable, If you want to use some variable globallyin your test, you have to declare those variable as Project/Project Suite in TestComplete. If we declare as local variable in number of tests, modification very dificult.

Let's have an example - Your test data is file paths that are specific to the computer, on which the project is opened,suppose if your test is runing on several machines (Network Suite or One another machine) , In this case it would be good if the file path is get from the computer where the test is running. You have to create a global script variable and change its value in the source code before running the test on each computer and this can be achived by Project/Project suite variable in TestComplete. Project/Project Suite variables can store their values between test run.

Project Variable : - Project variables only work for the current project. You can use them to share data between tests of various types included in your project, for instance, between scripts and keyword tests.

Project Suite Variable : - Project suite variables are similler to project variable, The only difference is that their values are shared with all projects belonging to the project suite.

1- Adding Project/Project suite variable - Select Project/Project suite from project explorer -> Right Click on it -> Go to Edit option -> Select Variables


Or Double click on Project/Project suite -> Select Variables tab

Here you can add your variable by following below step or code -  Go to Variables tab -> Right click on Temparary or Persistent variable Section -> Select New Item



Once you select "New Item" a row is added into the variables section where you can specify Variable Name, Variable Type, Variable Default Value, local Value and description.

Once you specify all the required details, your Project/Project suite variables are added. You can achived these by using below code (VBScript)

Project Suite Variable Syntax -

ProjectSuite.Variables.AddVariable "VarName","VarType"

Project Variable Syntax -

Project.Variables.AddVariable "VarName","VarType"
 
Example -

here we are adding a project/project suite variable named "DatasheetPath" and variable type is String.
 
ProjectSuite.Variables.AddVariable "DatasheetPath","String"

Project.Variables.AddVariable "DatasheetPath","String"

Similar you can add multiple variables -









 

Saturday 28 November 2015

Object Model in TestComplete (Automation Testing)

As a automation Tester, we all are following the Object model for automating the application but we won't be able to classified those object model based on uses. Most of the automation testers are having doubts the Object Model. In TestComlete or in Automation we are using below object model-
 
1- Component Object Model (COM) :-
2- Document Object Model (DOM)
3- Automation Object Model (AOM)
4- Test Object Model (TOM)

 
Let's have a quick view of each object model with classification..
 

Componenet Object Model (COM)

 Example-

 Set Obj = Sys.OleObject("Word.Application")
 Set Obj = CreateObject("Excel.Application")
 Set FSO = CreateObject("Scripting.FileSystemObject")

 

Document Object Model (DOM)

 Example -
 
 Set pageTitle = Sys.Browser.Page("http://google.com/").contentDocument.title
 Set ObjTextBox = Sys.Browser.Page("http://google.com/").FindChildByXpath("//input[@name='q']",Treu)

 

Automation Object Model (AOM)

 Example -

 Set objTestComplete = CreateObject("TestComplete.TestCompleteApplication")

 

Test Object Model (TOM)

 Test object model is a combination of Test Object and Run object information of the objects.

 

Sunday 7 June 2015

Download, Open and Save PDF file in TestComplete

I had a new experience in TestComplete, I had gone through a Scenario,where I have to Upload, Download, Open and Saved a downloaded PDF file.

I found downloading, Opening and Saving PDF file is complex process in TestComplete.


When I Click on "Download as PDF" file it ask me for Open/Save/Cancel like below-


OR



I have found some steps/solutions to make it easy. I am sharing those-  

1- Browser Setting  :- We have to  Enable/Disabled the corresponding Add-on/Plugin in a Browser It is depend upon your need. 

In my Scenario, I have to download pdf file, Open downloaded file and Save file as PDF. therefore I have to do same setting at Adobe Reader and Browser level.

1.1 -  In Adobe Reader, I have to make setting "Display PDF in Browser" is active, for that we have to follow below steps.

       1- Open Adobe Reader
       2- Go To Edit Tab
       3- Click on Preference option 
       4- Select "Display PDF in Browser" and Save.


1.2- In Browser,  I have to make Adobe Reader as Enabled, for making Adobe Reader Enable, follow the steps - 

    1- Open IE Browser
    2- Go to Tool Menu
    3- Go to Manage Add-ons 
    4- Select "Toolbar and Extensions"  from "Add-ons Type" section
    5- Select "All add-ons"  from "Show" section
    6- Select Adobe PDF Reader and Set Status as Enabled



In this way we can Open our Downloaded PDF file directly into the browser but still it is not saved. Thing is that - 

* TestComplete can not able to reorganized Save button in PDF file.
* Above solution is machine dependent.(We can not run same test on another machine without above setting) 

2 Scripting - Scripting is one of the best solution for this problem. In Descriptive Programming we can solve this problem without any machine dependency. In TestComplete we can write Descriptive programming using VBScript. (I am using VBScript for samble).

2.1-  First of all, we are searching "Download as PDF" button on my web page, If Button is found then we will click on "Download as PDF" button.


Sample Code - 

Set btnDownloadPdf  = Sys.Browser("iexplore").Page("*").FindChild(Array("objectType", " value"),Array("SubmitButton"," Download as PDF"), 1000)

IF (btnDownloadPdf.Exists) Then
btnDownloadPdf.Click()
Delay(1000)
End IF

2.2- Once We click on Download Button - Pop up will come and ask for Open/Save/Cancel. again we will search open button on pop- up and If button will found we will click on Open Button - 


Sample Code- 


Set btnOpenPdf  = Sys.Browser("iexplore").Page("*").FindChild(Array("objectType", " value"),Array("Button","Open"), 1000)

IF (btnOpenPdf.Exists) Then
btnOpenPdf.Click()
Delay(1000)

End IF

2.3- Once we click on Open button, PDF file will get open.but TestComplete not able to identify save button from PDF file so we can't use descriptive programming to save file, here we can save our file using an alternative way  WScript.Shell Programming -

Sample Code -


  objShellpdfSave = CreateObject("WScript.Shell")
 objShellpdfSave.SendKeys("+^S")
 Delay(5000)
 objShellpdfSave.SendKeys (Path and File Name)
 Delay(1000)     ;   
 objShellpdfSave.Sendkeys(ENTER)


This code may help you to save all type of file in your system using TestComplete. :)


Monday 30 June 2014

Data Driven testing with TestComplete.


Data-driven testing means running our automated tests script with different set of test data, it is simulate user actions over an application with different inputs.TestComplete allow us to perform data driven testing.

Let's consider in our application we are having 100 of users and we need to check login functionality of them, to find out which user credentials are working properly and which are not.

In order to complete this task, we can create a script in TC which would read each of the user credentials and try to login in application.

Let start step by step discussion of Data Driven Testing with TestComplete using CSV file-

CSV - comma-separated values (CSV) (also sometimes called character-separated values, because the separator character does not have to be a comma) file stores tabular data (numbers and text) in plain-text form. For creating a CSV file please refer : - http://www.computerhope.com/issues/ch001356.htm

CSV file one of the most popular data storage system for data-driven tests it is store comma-separated values.TestComplete supports this type of storage and allows us to retrieve data from it.

TestComplete provide CSVDriver() Method to create DDT driver (using DDT Driver object we can easily extract data which is stored in CSV file) for CSV file than contains values separated with your predefine delimiter character. (here Comma is separator)
Let us consider we have a CSV file (UserDetails.csv) along with number of UserId and Password.
First of all we need to initialize/create CSV Driver by using CSVDriver().
Syntax -
             DDT.CSVDriver("FilePath")

 Lets Consider we have saved (UserDetails.csv) file on path "D:\Automation\UserDetails.csv" 

Sub DDTCSVTest
             'create csv driver object
             DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
End Sub

We are having multiple set of data in csv file, TestComplete read those set of data one by one from the file, hence we need to check whether DDT driver is end of the csv file, which is provides access for DDT.

DDT.CurrentDriver.EOF - this method is used to determine where is your file end point. it will be return true when DDT Driver at the End otherwise false.

Sub DDTCSVTest
             'create csv driver object
             DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
             'Iterates through the records
             While Not DDT.CurrentDriver.EOF
             :
             :
             Wend
End Sub

TestComplete provide DDT.CurrentDriver.Value(index) method for reading data from the csv file.DDT.CurrentDriver.Value() method read column values at the index with 0 (zero)

Sub DDTCSVTest
 'create csv driver object
DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
While Not DDT.CurrentDriver.EOF
    TestObj.Textbox("txtUserName").SetText(DDT.CurrentDriver.Value(0))
    TestObj.PasswordBox ("txtPwd").SetText(DDT.CurrentDriver.Value(1))
    TestObj.SubmitButton("btnLogin").Click  
    
Wend
End Sub

DDT.CurrentDriver.Value(0) : - Reading user name from the csv file.
DDT.CurrentDriver.Value(1) : -  Reading Password from the csv file.

Note :- TestComplete considering first row as header of csv file.

Above code just read a single set of data from the csv file, but we need to read next set of data, if available, then use DDT.CurrentDriver.Next method. DDT.CurrentDriver.Next goes to the next set of data from the csv file.

Sub DDTCSVTest
'create csv driver object
DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
While Not DDT.CurrentDriver.EOF
     TestObj.Textbox("txtUserName").SetText(DDT.CurrentDriver.Value(0))
     TestObj.PasswordBox("txtPwd").SetText(DDT.CurrentDriver.Value(1))
     TestObj.SubmitButton("btnLogin").Click  
DDT.CurrentDriver.Next   
Wend
End Sub

This code would be read data as Username and Password from the second row (first row is header) then click on submit button and goes to the next record (if available) and it's reading all the records one by one until set of data is end.