defining functions in the test script

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

defining functions in the test script

Eleo-3
Is there some way I can define a JS function in the table for use by later rows?  I tried:

<tr>
        <td>storeEval</td>
        <td>function leadingZero(n) {var s='0'+n; return s.substring(s.length-2, s.length)}</td>
        <td>foo</td>
</tr>

and

<tr>
        <td>assertEval</td>
        <td>function leadingZero(n) {var s='0'+n; return s.substring(s.length-2, s.length)}</td>
        <td>null</td>
</tr>

but when I tried to use the new function on the next row:

<tr>
        <td>assertEval</td>
        <td>leadingZero(6)</td>
        <td>06</td>
</tr>

I got [error] Threw an exception: leadingZero is not defined

I also tried defining that function on the source tab in the head, but with the same result:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>reversalDate</title>
<script language="javascript">
function leadingZero(n) {var s='0'+n; return s.substring(s.length-2, s.length)}
</script>
</head>

I'd like to avoid adding external dependencies to the script, e.g., by defining the function in  user-extentions.js.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=3527&messageID=9892#9892

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: defining functions in the test script

Eleo-3
The following seems to work.  Is there a more elegant way?

<tr>
        <td>storeEval</td>
        <td>function(n) {var s='0'+n; return s.substring(s.length-2, s.length)}</td>
        <td>leadingZero</td>
</tr>
<tr>
        <td>assertEval</td>
        <td>storedVars['leadingZero'](6)</td>
        <td>06</td>
</tr>
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=3527&messageID=9986#9986

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: defining functions in the test script

Eleo-3
Of course, I can also use that function like this.  Maybe this is good enough.

<tr>
        <td>assertEval</td>
        <td>storedVars.leadingZero(6)</td>
        <td>06</td>
</tr>
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=3527&messageID=9987#9987

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]