Forum Discussion

2 Replies

  • Kitt's avatar
    Regular Contributor

    For starters, you need to declare the "homeScreen" var in each function, otherwise you are referencing a variable that is not defined and all your functions will fail. Secondly, I would try to avoid using mapped names as variables as it seems redundant and adds unnecessary extra lines in your code. EX: Instead of using...


    var browser=NameMapping.Sys.browser;
    var workbench=browser.pageAware3;
    var homeScreen=browser.pageAware2;
    var dashboardIcon=homeScreen.imageAmdawaaaach5baeaaaaalaaaaaa;


    just use...




    Remember, the point of name mapping is to make your tests easier to maintain and allows you to provide a shortened name/alias to your objects so that you don't have to create so many variables in your scrips - while also allowing you to use multiple conditions and properties to identify the object.


    As for general best practice, creating separate functions for small tasks like clicking an object, verifying its contents, or verifying properties, is probably overkill unless you are making it dynamically reusable throughout other tests or using BDD. Creating a single-line function for verifyRelationshipCol() and verifyAccountCol() seems unnecessary and I would consider just including these steps directly in the test case function. 


    Based on what you are attempting, I would try to create a verifyPageColumn(page, column) function that accepts different arguments for which page and column to search for, then apply some logic in your function to handle the different pages and objects accordingly - making it more reusable and dynamic. Something like:


    function verifyPageColumn(page, column) {
      var home = NameMapping.Sys.browser.pageAware2;
      // page handler
      switch(page) {
        case "loanAllocation":
        // example
        case "tradeExecution":
      // column handler
      switch(column) {
        case "Relationship":
          var object = home.panel7;
        case "Account":
          var object = home.FindElement("//span[contains(., 'Account')]");
        // example
        case "Trade":
          var object = home.FindElement("//div[contains(., 'Trade')]");
      // verify object properties
      aqObject.CheckProperty(object, "contentText", cmpEqual, column);
    function TestCase1() {
      verifyPageColumn("loanAllocation", "Relationship");
    function TestCase2() {
      verifyPageColumn("loanAllocation", "Account");
    function TestCase3() {
      verifyPageColumn("tradeExecution", "Trade");


    NOTE: I've included extra examples to show how you can expand the logic to handle multiple pages and objects. Not that this method is any better than your approach, really it just depends on your project, coding style, and how you are identifying areas that are prime for optimization (how frequently do you preform this step, can this step contain different values/outcomes, can this step be broken into smaller reusable steps if it becomes too complex, etc).

    • neelam's avatar
      Occasional Contributor

      Kitt : I have been using below approach but I have observed that most of times it becomes cumbersome in script when we have so many object identifiers and it is bit difficult for someone to read the object as pageAware


       and for I am using BDD approach where I will use these small functions and call them in step definitions.