Forum Discussion

jmcwhinney's avatar
jmcwhinney
Contributor
12 years ago

Creating reusable functions for Navigation Menu in webpage

Hello,



I am trying to automate testing of an asp.net application

There are multiple pages which TestComplete creates Aliases for.

Aliases.browser.pageUserRegistration2

Aliases.browser.pageEpartstorePartsSearch

etc...



Each of these pages contains the same navigation menu.



I would like to create a function that allows me to click one of the navigation options regardless of which page I am starting from.

To make the function truly generic and usable at any time, I do not want to use a reference to a specific page within the function.

eg. Aliases.browser.pageEpartstorePartsSearch.navigationmenu.click()



I need to the function to be more like:

Aliases.browser.GenericPage.navigationmenu.click()





I tried creating a generic name mapping for this purpose, but then all future recordings start mapping to the generic name mapping.



Any suggestions?



Thanks!

- James







Is



2 Replies

  • I had a similar situation with some global navigation. We have a header bar with a Logout link, but I didn't want to have to map it for every page. What I ended up doing was creating a function that just looks for the logout link on whatever page is loaded. My function is below, if it can help you. If yours is a menu, you could just have it accept a parameter of what menu item to select and pass that in to the arrValues array instead of my "Logout".






    function logout()


        call aliases.browser.page("*").Wait


        delay 3000


        


        arrProps = array("objecttype", "contenttext", "visible")


        arrValues = array("link", "Logout", true)


        set logoutLink = aliases.browser.find(arrProps, arrValues, 9, true)


        if not logoutLink is nothing then


            logoutLink.click


            logout = true


        else


            delay 5000, "Waiting for logout link"


            set logoutLink = aliases.browser.find(arrProps, arrValues, 9, true)


            if not logoutLink is nothing then


                logoutLink.click


                logout = true


            else


                log.message "Failed to find the logout link"


                logout = false


            end if


        end if


    end function


  • Thanks! that looks like it could work.

    I will give it a try and accept your answer if it works,



    Cheers,

    - James