Forum Discussion
AlexanderM
Staff
15 years agoHello Omer,
As far as I understand, you have a set of pages that have a similar structure and should be processed in the same manner. It means that you need to access some common objects of these pages in the same manner. It is possible to use the Name Mapping feature for this purpose.
However, there is a small issue with this approach: by default, when recording a test, TestComplete automatically maps each page using its URL property, so you'll have a separate branch for each page in the Name Mapping tree. As a result, every test you will record will address a different mapped Page object. So, you will not be able to run a test with a different Page object, even though the actions are the same and the structure of the mapped objects is the same.
There is a solution though:
You can avoid creating multiple Page objects in the Name Mapping tree. Instead, you can have a Page object mapped in a special way that will match the web page currently loaded in the web browser. In this case, any recorded test will work with any page, if the object structure is actually the same, as you mentioned.
You can do this by changing the mapping criteria for the mapped Page object. Instead of using a specific URL in the mapping criteria list, you can make TestComplete read the URL value to be used for identification from a project variable. To learn how to use a project variable as a data source for a mapping criteria value, please see the Specifying Identification Property Values help topic.
So, using this approach will make the following scenario possible:
- you record a script with page A;
- you create a project variable called CurrentURL;
- in the mapping criteria of the mapped PageA object, you specify the CurrentURL variable as a data source for the URL value;
- when you need to run your test with page B, which has exactly the same object structure as page A, you modify the CurrentURL project variable;
- as a result, the mapped PageA object will now match page B, and all the tests will reference objects inside page B.
It is possible to change the CurrentURL variable's value from script, which allows you to test a set of pages with the same object structure one after another in a batch. The snippet below illustrates how to adjust mapping criteria by using a project variable:
var url = "http://localhost:60673/UI/Pages/Page.aspx";
iexplore.ToURL(url);
Project.Variables.CurrentURL = url;
//work with page objects here
Also, you can create a text file that will contain URLs of the pages to be tested and organize iterating through them by using the CSVDriver object. Suppose that each line of the text file contains a single URL (please note that CSVDriver treats the values of the first line as column names).
var driver = DDT.CSVDriver("C:\\test\\TestUrl.txt");
while(!driver.EOF()){
url = driver.Value(0);
iexplore.ToURL(url);
Project.Variables.PageUrl = url;
//work with page objects here
driver.Next();
}
DDT.CloseDriver(driver.Name);
See also:
Specifying Identification Property Values
Data-Driven Testing - Basic Concepts
Please let us know if this is what you need.