I'm using Test complete for automation. I create class : "Common" with code :
function Read_Excel_Login(){
var Driver1 = DDT.ExcelDriver("C:/Users/NVA/Downloads/leave.xls","login",true);
}
function Login()
{
if( Driver1.Value(3)==2)
{
page = Aliases.browser.pageHrmtestSpsSymfonyWebIndexPhp2;
page.Wait(5000);
}
else
{
page= Aliases.browser.pageHrmtestSpsSymfonyWebIndexPhp;
page.Wait(5000);
}
page.contentDocument.Script.$("#txtUsername").val(Driver1.Value(0)).change();
page.contentDocument.Script.$("#txtPassword").val(Driver1.Value(1)).change();
page.contentDocument.Script.$("#btnLogin").click();
}
I Create other class : "Main" for login user and call class : "common" with code:
var Common = require("Common");
function Main()
{
Common.Read_Excel_Login();
while(!Driver1.EOF())
{
Common.Login();
Driver1.Next();
}
}
Error appear after run:
ReferenceError
Driver1 is not defined
How to fix this problem ? Thanks.
If you put a breakpoint at the start of your code and step through it, it might help you find the issue.
The issue is that you've declared
Driver1
in the functionRead_Excel_Login()
and then that function goes out of scope and you referenceDriver1
in the functionLogin()
where it's not defined.I would define
Driver1
inMain()
and then haveRead_Excel_Login()
return a driver instance. Then you can passDriver1
toLogin()
where it can be used.I also changed the name of the driver to be more specific,
ExcelDriver
instead ofDriver1
.It's been a long time since I've done anything with TestComplete so I think this syntax is mostly correct.