Ask a Question

Script extension method parameter

SOLVED
mikakoistinen
Contributor

Script extension method parameter

Hi,

I tried to make my 1st script extension.

function cleanStr(s)
{
  s = aqString.Replace(s, chr(27), '');
  s = aqString.Replace(s,chr(2), '');
  s = aqString.Replace(s,chr(28), '');
  s = aqString.Replace(s,chr(14), '');
  return s;
}

same code works okay if used directly in jscript, but if it is extension I get error Value must be an object (or similar, error is in  native language)

i call it like (skjstrutils is the extension )

 showmessage(skjstrutils.cleanStr('aaaaa'));

 

Jeemly - Dream Big
https://jeemly.com/
1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Script extension method parameter

The error message is a bit misleading.  The problem is not with the parameter, it's with your use of the chr method.  That method is a method provided within the TestComplete environment and is not available within script extensions.

 

To do what you want to do, use the native JScript method String.fromCharCode like so

 

function cleanStr(s)
{
  s = aqString.Replace(s, String.fromCharCode(27), '');
  s = aqString.Replace(s,String.fromCharCode(2), '');
  s = aqString.Replace(s,String.fromCharCode(28), '');
  s = aqString.Replace(s,String.fromCharCode(14), '');
  return s;
}

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

6 REPLIES 6
AshokKumarSahoo
Contributor

Re: Script extension method parameter

@mikakoistinen As per my understanding you need to create a run time object  within extension package to access the methods.Create a filename.xml and keep within extentesion folder,refer the below sample code for your reference.Try with this approcah it might be help you.

 

<?xml version="1.0"?>
<ScriptExtensionGroup Name="">
<Category Name="RunTime Objects">
<Script Name="sciptunitname.js">
<RuntimeObject Name="skjstrutils">
<Method Name="cleanStr" Routine="cleanStr">Method Desciption</Method>
</RuntimeObject>
</Script>
</Category>
</ScriptExtensionGroup>

 

After create the .xml file,try to access your method like below.

Runtimeobjectname(skjstrutils).MethodName(cleanStr)

 

Thanks ,

Ashok

 

tristaanogre
Community Hero

Re: Script extension method parameter

The error message is a bit misleading.  The problem is not with the parameter, it's with your use of the chr method.  That method is a method provided within the TestComplete environment and is not available within script extensions.

 

To do what you want to do, use the native JScript method String.fromCharCode like so

 

function cleanStr(s)
{
  s = aqString.Replace(s, String.fromCharCode(27), '');
  s = aqString.Replace(s,String.fromCharCode(2), '');
  s = aqString.Replace(s,String.fromCharCode(28), '');
  s = aqString.Replace(s,String.fromCharCode(14), '');
  return s;
}

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

tristaanogre
Community Hero

Re: Script extension method parameter

@AshokKumarSahoo Your usage of the runtime object is incorrect.  Once it's wrapped with the description.xml file (it needs to be named, specifically, as description.xml), you can just simply call it as mika has.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
mikakoistinen
Contributor

Re: Script extension method parameter

Thanks, @tristaanogre. It works now.

 

Jeemly - Dream Big
https://jeemly.com/
tristaanogre
Community Hero

Re: Script extension method parameter

Excellent!  Glad to hear it.

 

The chr function is not called out in the Script Extension help documentation as excluded so understandably this was a confusing point.  However, lots of other stuff IS included.

 

https://support.smartbear.com/testcomplete/docs/working-with/extending/script/objects-reference/inde...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
AshokKumarSahoo
Contributor

Re: Script extension method parameter

@tristaanogreThanks for your clarification.Sorry for inconvenience.

cancel
Showing results for 
Search instead for 
Did you mean: