Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function That Creates WebLink Variables
#1
Not Solved
I am thinking of doing something I am not sure if it is possible - perhaps not the best practice even, but nonetheless want to give it a try.

I have a function library and I have the action in which I do the main scripting, obviously calling functions from the library. 

Originally in my action, the code looked something like this:

Code:
Browser("Browser").Page("Page").WebElement("Element").Click


I have, however, changed it to this:

Code:
    Set WebLink = Browser("Browser").Page("Page")
    
    WebLink.WebElement("Element").Click


I did this because i feel that it has a cleaner look with "less" code in each line. 

I know that I can code a function to do this:


Code:
    Public Function myLink(WebLink)
    
    Set WebLink = Browser("Browser").Page("Page")
    
    End Function


Then in my action, I do a call just once at the top:

Code:
    Call myLink(WebLink)
    WebLink.WebElement("Name").HighLight 


However, I was thinking that in some instances, I would have different page names, for example:

Code:
    Browser("Browser").Page("Page1")
    Browser("Browser").Page("Page2")
    Browser("Browser").Page("Page3")

So perhaps, creating a function that would store my variables and then I am able to call the variables could be an alternative.

My function could look like this:

Code:
Public Function myLinks(WebLink)
   
    Dim Pages(): Pages = ("Login","CreateUser","SelectOption","DeleteUser",)
   
    Browser("Browser").Page(Pages())
   
    For Each Elem In Pages
       
        Set WebLink = Browser("Browser").Page(Pages())
       
    End For
   
    End Function


Then in my action, I use it like this:

Code:
Call myLinks(WebLink)
        
    Login.WebElement("Element").Click
    CreateUser.WebElement("Element").Click
    SelectOption.WebElement("Element").Click
    DeleteUser.WebElement("Element").Click


I know that what I have is probably illogical but if something like this could perhaps work, I would like to give it a try.
Reply
#2
Not Solved
Except perhaps things in the later part, I don't find issue with the script above. What is stopping you to use this?
Reply
#3
Not Solved
(07-12-2018, 08:33 PM)Ankur Wrote: Except perhaps things in the later part, I don't find issue with the script above. What is stopping you to use this?

Thank you for the reply. I wasn't able to test this the other day, so I was wondering what the community would have to say about whether it would work or not. I do believe I can get it to work, so will update the post at a later stage Smile
Reply
#4
Not Solved
Yeah, it's good to validate our thought process at times. Smile

Feel free to ask your queries over here in case you get stuck! All the best.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,977 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  Array as User-Defined Environment Variables Arena 3 4,274 04-16-2012, 09:19 AM
Last Post: sshukla12
  programming to use different external file of environment variables bundfromnj 1 3,979 01-19-2012, 05:32 PM
Last Post: SteveS
  How to store all output values in different variables Jyobtech 4 4,755 10-13-2010, 11:23 AM
Last Post: KavitaPriyaCR
  Using DP with variables pjeigenn 6 4,516 07-19-2010, 07:32 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)