Edit: Hey, wouldn't you know it. I just spotted some syntax errors to fix
Hi Preetha
Something you need to be aware of that often gets users coming from OO environments. You can't pass objects by reference in quite the same way. See https://stackoverflow.com/questions/13104494/does-javascript-pass-by-reference
Your code seems to indicate you are trying to use the openurl() function from OpenFB unit as an object with page being one of the properties of the object. This won't work, since "page" is not exposed if you are looking at it from an OO outlook. This shouldn't be too much of a surprise. This is a scripting language rather than an OO language after all.
There are two potential ways of working round this I can think of off the top of my head:
1. Return the "page" object as AlexKaras suggests
2. Return the "page" as a property of the pseudo object:
//OpenFB unit
function FBPage()
{
//This bit makes it behave like an object:
if (!(this instanceof FBPage))
{
return new FPPage();
}
Browsers.Item(btChrome).Run("https://www.facebook.com/");
var browser = Sys.browser();
this.page = browser.Page("*facebook.com");
//the same thing, but as a function. Usefull if you need to do more than jsut get the page
this.GetPage = function()
{
Log.Message("Getting the Page");
return this.page;
}
//More on this later
this.Fetch = funtion()
{
return this;
}
}
//USEUNIT OpenFB
function mandatory_check()
{
FBPage().page.NativeWebObject.Find("name","websubmit","BUTTON").Click();
//TC IDE can't pick up the .page - If you want TC IDE to see the page property, you are looking at script extentions
//The same thing:
FBPage().GetPage().NativeWebObject.Find("name","websubmit","BUTTON").Click();
//Both these methods create a new "Instance" of the object though, meaning it will rerun and refind stuff
//which can take some time. This is where fetch comes in
var openFBObj = FBPage().Fetch();
openFBObj.page.NativeWebObject.Find("name","websubmit","BUTTON").Click();
openFBObj.GetPage().NativeWebObject.Find("name","websubmit","BUTTON").Click();
//Once again, don't depend on TC to pick up these "properties" and "methods"
}
I can't help but notice though that this function is extremely narrowly focussed. You may want to consider making openurl a function with parameters and move it into a more generic unit e.g.
//Unit PageNavigation
function OpenPage(browser,url,pagename)
{
if(!(this instanceof OpenPage))
{
return new OpenPage(browser,url,pagename);
}
Browsers.Item(browser).Run(url);
var browser = Sys.browser();
var page = browser.Page(pagename);
this.GetPage = function()
{
return page;
}
this.Fetch=function()
{
return this;
}
this.Click = function()
{
try
{
page.NativeWebObject.Find("name","websubmit","BUTTON").Click();
return true;
}
catch(e)
{
Log.Error(e);
return false;
}
}
}
//Unit B
//USEUNIT PageNavigation
function mandatory_check()
{
if(OpenPage(btChrome,"https://facebook.com/","*facebook.com").Click())
{
Log.Message("It worked !");
}
else
{
Log.Error("It Failed !");
}
}