Answered

Is there a way to access Subject 7 variables from within an EXECUTE_JAVASCRIPT script command?

Hello,

I would very much like to be able to access the local Subject 7 variables from within a Javascript file. For example, I have a Subject 7 variable I obtained from a webpage using the GET_VALUE command. However, I would very much like to do some processing on the variable by calling a certain Javascript file. Is this possible? 

0
3 comments
Avatar
Rex Feizi

Hi. 

What do you mean by "Javascript file"?

There is a command EXECUTE_JAVASCRIPT that runs javascript commands that are provided as arguments. If you have read a value using GET_WEB_VALUE into say var, then you can use @var in the EXECUTE_JAVASCRIPT command. 

 

If this doesn't help, please elaborate on exactly what you want to do with a more concrete example. 

 

Thanks, 

 

--Rex

0
Comment actions Permalink
Avatar
Justin Tam

Hi Rex,

Thanks for the quick reply. That is a good example of what I'm talking about, I should have specified the EXECUTE_JAVASCRIPT command instead. 

I tried to use, for example, @variable in a javascript command after defining it using the SET_VAR command, though I get thrown a syntax error as variables are only not allowed to start with '@'. Excluding the '@' does also not work. Any suggestions?  

Here's a screenshot of what I'm trying to do, and how I'm going about it:

 

Thanks for the help,

Justin

0
Comment actions Permalink
Avatar
Rex Feizi

Justin, 

You are most welcome. 

Javascript expression cannot start with "@", it doesn't make sense. What exactly do you want to do in JS? It's best to define a JS variable and assign the variable you defined in SET_VAR directly. it will make your JS code clean and easy. 

Here is an example that you can copy and paste in a new test case advanced view to try out: (Advanced view is the Microscope icon in the test case tool bar)

Hope this helps, please let us know how it goes. 

WEB GOTO_URL "https://www.subject-7.com" HALT ON ERROR
SET VARIABLE myvar VALUE STATIC "hello JS" HALT ON ERROR
WEB EXECUTE SCRIPT "var myText = '@myvar';\nalert(myText);" HALT ON ERROR

 

 

 

0
Comment actions Permalink

Please sign in to leave a comment.