Forum Discussion

omerj28's avatar
omerj28
Occasional Contributor
14 years ago

Repeating common operations on different pages of a web application

On each page of my web application, I have a set of buttons used for common functions like: Refresh, Email, Export, Print and Help etc.

How can i create a Script or Keyword test such that the same test can be run for each page in the application with little modification. Are there going to be any particular variables whose values can be dynamically changed to accommodate different pages within the application? Can it be done through inputting the the page name variables through a text file and then the test engine can perform the same set of operation once it has navigated to the appropriate page?

I mean to say, if the name of the page is changed in the ToURL statement (http://localhost:60673/UI/Pages/Page.aspx), then the test engine might proceed with the next steps once a certain page loads?



A quick reply will be highly appreciated.

regards

3 Replies


  • Hello 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.
  • Hi,



    You can use OnWebPageDownloaded Event. Use this event, check common buttons availability under this event, if buttons are there execute the button's functionality. For more information you can check OnWebPageDownloaded Event help.



    Hope it will resolve you problem.
  • omerj28's avatar
    omerj28
    Occasional Contributor
    Dear Mazhar,

    Thanks for the OnWebPageDownloaded event tip...i'll give it a try and let you know if it works for me.



    I needed some information about CSTE exam. I heard that this exam is not offered in Pakistan. How did you manage to get the certification? What material you used to prepare for this exam. Whats the Fee for this exam and can you please guide me a little about the registration process. Is there an institution in Lahore that offers preparation/training for this Exam?