cancel
Showing results for 
Search instead for 
Did you mean: 

Script extension problems (jscript)

SOLVED
Highlighted
Contributor

Script extension problems (jscript)

Hello all,

 

 

Trying to implement a script extension (using TC 10.6, jscript as language) i encounter some problems and need your help.

 

Attached are the descrption.xml and the extension source code where the problems besides.

 

When i use built-in functions, e.g. Log object, or when i define variables, it seems that is not working:

- the pmNormal priority (or other pm level) is not recognized, i must use integer value instead.

- the log attributes defined in the script is ignored (variable logWarning or logInfo used as log attributes doesn't work but no error raised).

- the Log.Enabled=false seems to be inoperant, i still have the log entry 'unable to find object'.

 

The same code in a standard sj unit works very well.

 

Any idea why ?

 

Thanks a lot.

 

 

Un sourire et ça repart
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Script extension problems (jscript)


@bbi wrote:

Ok about pm as pseudo constant and log attributes initialization.

 

Perhaps in help file would be interesting to add the info about limitations onto Initialize/Finalize function.


We'll add this to the docs, thanks.

 


bbi wrote:

 

About log enabled the test is quick to do, add my script extension language to whatever project, make a call to an unexisting object like:

qa.system.findIt(Sys.Browser("iexplore"), 'test', 'test', qa.system.duration.seconds, 3, true);

 

And in your log you should have an entry like this:

Unable to find the object Sys.Browser("iexplore"). See Additional Information for details. 11:48:59 Normal


This is the same as:

 

var p = Sys.Browser("iexplore");
qa.system.findIt(p, ...);

If Internet Explorer isn't running, the code errors out at Sys.Browser("iexplore") and doesn't even reach your search function. The main script still needs to use some form of error handling or error suppression. For example:

 

qa.system.findIt(Sys.WaitBrowser("iexplore"), ...);
qa.system.findIt(Aliases.browser, ...);

// or something like
var browser = qa.system.findIt(Sys, "ObjectType", "Browser", ...);
qa.system.findIt(browser, 'test', 'test', qa.system.duration.seconds, 3, true);

 


Helen Kosova
SmartBear Technical Writer
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

5 REPLIES 5
Highlighted
Moderator

Re: Script extension problems (jscript)

Hi bbi,

 


@bbi wrote:

 

- the pmNormal priority (or other pm level) is not recognized, i must use integer value instead.


That's because the pmNNN constants are defined in the BuiltIn object/namespace, which isn't available in script extensions. But you can define these constants in your code:

 

var pmNormal = 300;
var pmHigher = 400;
...

 


@bbi wrote:

 

- the log attributes defined in the script is ignored (variable logWarning or logInfo used as log attributes doesn't work but no error raised).


Log.CreateNewAttributes and the Log object in general can't be used in the initialization and finalization functions. This is because Log exists only during test runs, but the initialization/finalization functions can fire at arbitrary moments -- for example, at design time when you open Code Completion for qa.system.


Moving the logInfo/logError/etc. creation code from the init function into the corresponding getter functions should do the trick:

 

var logInfo;

function Initialize() {
  logInfo = null;
  ...
}

// Log attributes for informational log
function GetlogInfo() {
  if (logInfo == null) {
    logInfo = Log.CreateNewAttributes();
    logInfo.BackColor = 0xF0CAA6; // Sky blue
    logInfo.FontColor = 0x000000; // Black
  }
  return logInfo;
}

function findIt(...) {
  ...
  Log.Message(...,  GetlogInfo()); // Use the getter function
}

@bbi wrote:

 

- the Log.Enabled=false seems to be inoperant, i still have the log entry 'unable to find object'.


I can't reproduce this so I'm not sure what's happening. Can you share sample code that demonstrates the issue?


Helen Kosova
SmartBear Technical Writer
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Contributor

Re: Script extension problems (jscript)

Ok about pm as pseudo constant and log attributes initialization.

 

Perhaps in help file would be interesting to add the info about limitations onto Initialize/Finalize function.

 

About log enabled the test is quick to do, add my script extension language to whatever project, make a call to an unexisting object like:

qa.system.findIt(Sys.Browser("iexplore"), 'test', 'test', qa.system.duration.seconds, 3, true);

 

And in your log you should have an entry like this:

Unable to find the object Sys.Browser("iexplore"). See Additional Information for details. 11:48:59 Normal  

 

But normally you should'nt have it (Log.Enabled = false) no ?

Hmm .. perhaps the test (ParentObject == undefined) is the root problem ?

 

BTW if you have any comment about my search function, i'll greatly appreciated it.

 

Un sourire et ça repart
Highlighted
Moderator

Re: Script extension problems (jscript)


@bbi wrote:

Ok about pm as pseudo constant and log attributes initialization.

 

Perhaps in help file would be interesting to add the info about limitations onto Initialize/Finalize function.


We'll add this to the docs, thanks.

 


bbi wrote:

 

About log enabled the test is quick to do, add my script extension language to whatever project, make a call to an unexisting object like:

qa.system.findIt(Sys.Browser("iexplore"), 'test', 'test', qa.system.duration.seconds, 3, true);

 

And in your log you should have an entry like this:

Unable to find the object Sys.Browser("iexplore"). See Additional Information for details. 11:48:59 Normal


This is the same as:

 

var p = Sys.Browser("iexplore");
qa.system.findIt(p, ...);

If Internet Explorer isn't running, the code errors out at Sys.Browser("iexplore") and doesn't even reach your search function. The main script still needs to use some form of error handling or error suppression. For example:

 

qa.system.findIt(Sys.WaitBrowser("iexplore"), ...);
qa.system.findIt(Aliases.browser, ...);

// or something like
var browser = qa.system.findIt(Sys, "ObjectType", "Browser", ...);
qa.system.findIt(browser, 'test', 'test', qa.system.duration.seconds, 3, true);

 


Helen Kosova
SmartBear Technical Writer
________________________

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

Highlighted
Contributor

Re: Script extension problems (jscript)

Ok i understand, thanks a lot.

 

 

Attached file are corrected revision, free to use by everyone.

Un sourire et ça repart
Highlighted
Occasional Contributor

Re: Script extension problems (jscript)

Thank you for sharing your code bbi. I've been thinking about converting some of my shared script units into script extensions, so this is very useful information. Your log functions are a nice touch. Also, your findIt function is very similar to one of my functions that I use for finding objects (so I don't use NameMapping); I never knew about the HISUtils object before (I used my own homebrew code for timings), but I think your way is much better.

Cheers! / Salute!

 

New Here?
Join us and watch the welcome video:
Building with the Collaborator API

Help Documenation
The Collaborator API is a JSON-RPC API that lets you integrate with Collaborator 9.0 and above. For more information about how the API works, check out the API description here:


Sample Plugins
For an example of an add-in that uses the API, take a look at the Microsoft Word Add-in for Collaborator:


We list all the great plugins our network has already built on this page on the SmartBear website.

Labels