cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic function names

SOLVED
Highlighted
Occasional Contributor

dynamic function names

Hi Everyone,

 

TestComplete 14, project in JS

 

We're currently testing an app on Android and are trying to get ourcode dynamic, so that the Device can become some sort of global variable (execution environement related) that would have impacts on the way we'll execute the tests.

Unfortunately, we're not always able to do so, using testComplete.

 

Let me give you a clear example.

In some of our tests, we're using the Regions to compare screenshots taken in advance, with the actual screen while the test is executing.

Code :

function loginImageComparison(){Regions.loginF8331.Check(Aliases.Device.Android.login)};

This works very well with 1 Device. But when you change for a different one, you're likely to get the following

Output error : "The images are not equal. The size of the images is different."

 

 

All Right, we can take 1 image per Device, called something like "myImageDeviceName" and have the end of the "Devicename" part vary in our script.

 

So we scripted the following code :

function loginImageComparison(){
var loginScreenName, loginScreenImage;
loginScreenName = "login" + Mobile.Device().DeviceName;
loginScreenImage = Regions.loginScreenName;
loginScreenImage.Check(Aliases.Device.Android.login)

};

Output error : TypeError: Cannot read property 'Check' of undefined

loginScreenName, as a string, is not computed by testComplete. LoginScreenName is undefined.

 

So we tried the following, to make sure :

function loginImageComparison(){
var loginScreenName, loginScreenImage;
loginScreenName = "login" + Mobile.Device().DeviceName;
loginScreenImage = "Regions." + loginScreenName;
loginScreenImage.Check(Aliases.Device.Android.login);
};

Output error : TypeError: imageReference.Check is not a function

Without surprise, loginScreenImage, as a string, is not a function.

 

So is there a way to "variabilize" methods of testComplete ?

This could be the same for nameMapping for instance : Aliases.objectDevice with the "Device" used as a variable.

 

Regards,

Paul

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: dynamic function names

Try the so-devil-and-must-be-hidden-because-too-powerful function eval() ...

 

loginScreenImage = eval("Regions." + loginScreenName);

Un sourire et ça repart

View solution in original post

Tags (1)
3 REPLIES 3
Highlighted
Community Leader

Re: dynamic function names

Try the so-devil-and-must-be-hidden-because-too-powerful function eval() ...

 

loginScreenImage = eval("Regions." + loginScreenName);

Un sourire et ça repart

View solution in original post

Tags (1)
Highlighted
Occasional Contributor

Re: dynamic function names

😄
I guess, for "real" developpers, that was a non problem.

Thank you for the tip.

Cheers

Highlighted
Community Leader

Re: dynamic function names

In fact eval() is so powerful that a bunch of real dev avoid it .. but well used it's a magic wand !

And yes, this come from pure dev world 😉

 

 

 

 

Un sourire et ça repart

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors