How do I declare and increment a variable with Selenium?

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

How do I declare and increment a variable with Selenium?

Eleo-3
I am trying to automate a creation process.
For example,

When I create the user TESTUSER1 and complete the process. Then I want to loop back to the beginning of the script and start over and create TESTUSER2.

I can store 1 as the SUFFIX
I think I can put them together with javascript{'TESTUSER' + ${SUFFIX} }

But I don't know how to increment the SUFFIX.

Any info would be greatly appreciated. (that also means any recommended books that would help me to learn javascript)

Thanks,

Rod
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=1269&messageID=3630#3630

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
Yea I am actually running into the same problem. Any info on this would be a huge huge help.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
In reply to this post by Eleo-3
You can use javascript within your test script. If you just do something like {suffix++} that should work for you to increment.

I have found something in the forum about other javascript things to get you going.

http://forums.openqa.org/thread.jspa?messageID=18681&#18681

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
I have used this. For some reason I cannot get the while loop to work. I don't have any errors in my test. It just doesn't loop back. Any ideas? Here is what I have so far:

<tr>
        <td>store</td>
        <td>0</td>
        <td>loopNo</td>
</tr>
<tr>
        <td>while</td>
        <td>${loopNo} < 4</td>
        <td></td>
</tr>
<tr>
        <td>type</td>
        <td>firstName</td>
        <td>TestSel0 ${loopNo}</td>
</tr>
<tr>
        <td>type</td>
        <td>lastName</td>
        <td>TestSel0 ${loopNo}</td>
</tr>
<tr>
        <td>storeEval</td>
        <td>${loopNo} + 1</td>
        <td>loopNo</td>
</tr>
<tr>
        <td>endWhile</td>
        <td></td>
        <td></td>
</tr>

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
I tested your code with following modification (for my convenience):

> {quote:title=amikolaj wrote:}{quote}
> <tr>
> <td>type</td>
> <td>firstName</td>
> <td>TestSel0 ${loopNo}</td>
> </tr>
> <tr>
> <td>type</td>
> <td>lastName</td>
> <td>TestSel0 ${loopNo}</td>
> </tr>

<tr>
        <td>echo</td>
        <td>TestSel0 ${loopNo}</td>
        <td></td>
</tr>
<tr>
        <td>echo</td>
        <td>TestSel0 ${loopNo}</td>
        <td></td>
</tr>

I got the expected results by running it under Selenium Testrunner in IDE 0.8.7. Note that "while" command cannot run directly in Selenium IDE. Alternatively you can use "while" in Selenium core.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
> <tr>
> <td>store</td>
> <td>0</td>
> <td>loopNo</td>
> </tr>
> <tr>
> <td>while</td>
> <td>${loopNo} < 4</td>
> <td></td>
> </tr>
> <tr>
> <td>type</td>
> <td>firstName</td>
> <td>TestSel0 ${loopNo}</td>
> </tr>
> <tr>
> <td>type</td>
> <td>lastName</td>
> <td>TestSel0 ${loopNo}</td>
> </tr>
> <tr>
> <td>storeEval</td>
> <td>${loopNo} + 1</td>
> <td>loopNo</td>
> </tr>
> <tr>
> <td>endWhile</td>
> <td></td>
> <td></td>
> </tr>

I'm not aware of any support in Selenium for "while" and "endWhile"  
commands. Is this some sort of user extension?


Patrick Lightbody
Selenium Remote Control Creator

Check out the *new* HostedQA:
  * See screenshots and movies of your Selenium tests with RealityCheck.
  * Quickly verify your site design and performance with RealityView.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
In reply to this post by Eleo-3
Ah, nevermind... I see it is the flowControl extension.

My personal opinion is that if you find yourself using flowControl,  
it may be time to upgrade to Selenium Remote Control :)


Patrick Lightbody
Selenium Remote Control Creator

Check out the *new* HostedQA:
  * See screenshots and movies of your Selenium tests with RealityCheck.
  * Quickly verify your site design and performance with RealityView.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
In reply to this post by Eleo-3
I ran it in Selenium Testrunner using both IDE 0.8.7and the Testrunner in core, and it ran fine but still no loop. Does Testrunner have the ability to run a loop? There must be something small that I am missing. Any ideas?

I am trying to fill out a form for an online website, then submit the form. After the form is submitted, a "thank you" page is displayed. Here is where i want to go back to the beginning and open the page again so I can fill out the form with a different name. This is where I would use the following to change the names:

<tr>
        <td>type</td>
        <td>Mini_Form0_LastName</td>
        <td>Ada1Testa${loopNo}</td>
</tr>

and

<tr>
        <td>storeEval</td>
        <td>${loopNo} + 1</td>
        <td></td>
</tr>

Also I tried the echo command and it was not recognized

Any help would be great. Thanks a lot for your responses already

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
> {quote:title=amikolaj wrote:}{quote}
>
> <tr>
> <td>storeEval</td>
> <td>${loopNo} + 1</td>
> <td></td>
> </tr>
>

As far as I can see the name of the variable is missing:
storeEval | ${loopNo} + 1 | loopNo

Does this help?

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
Yup I tested this again it works great. Thanks everyone for helping!

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
In reply to this post by Eleo-3
Hi,

I am also working on new creation where I need script to increment the user number each time when script is being run. For ex: user1, user2, user3...). I tried above scenario but I am getting error " while command not found". If  I remove while/endwhile statement, script is running without any error and it takes the same value everytime.

Declaring Javascript as variable( as mentinoed above) also do not work for me. I need this urgent. Can anyone help?

Thanks in advance.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
The while command is part of the flowControl extension as mentioned above here. Make sure you have downloaded and applied the extension.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
Hi

I downloaded the flow control extensions from following link. first two are giving some error So I am unable to apply but the last one I could add it . Now I have while option in IDE but I get an error while I try to execute it. I tried to execute using testrunner.

http://wiki.openqa.org/pages/viewpageattachments.action?pageId=379

Error I get:

# [info] Executing: |while | ${loopNo}<4 | |
# [error] Unexpected Exception: message -> currentCommandRow is not defined, fileName -> file:///C:/Selenium/core/scripts/user-extensions.js, lineNumber -> 162, stack -> ("0<4","")@file:///C:/Selenium/core/scripts/user-extensions.js:162 apply([object Object],[object Array])@:0 ("0<4","")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:307 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (-10)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 apply([object Object],[object Array])@:0 (-10)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 @:0 , name -> ReferenceError

Is this the right extension? if not, can you pls point me to the right one.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
I think goto_sel08.js is the correct one. Perhaps you need to add it into user-extensions.js and add that file via

SIDE Options menu --> Options --> Selenium Core extensions option

when using the IDE with the TestRunner.

Dod you try that?

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
I tried adding goto_sel08.js to my user_extensions.js and also added to SIDE ->options menu but getting error on line 23. I am new to Javascript and don't know how to fix it.

Error:" HtmlRunnerTestLoop' is not defined" Code: 800A1391 Source: Js runtime  error"

Any suggestion? ..

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
Does the error appear only when you add it with both the options? You can try either Selenium Core extensions or SIDE extensions option.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

Eleo-3
yes. It happens with both. somehow I manage this error now. So 'while' works but I am getting error that 'endwhile' not found. I am not sure what i did was right or not.

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

Reply | Threaded
Open this post in threaded view
|

Re: How do I declare and increment a variable with Selenium?

                                                                                                                       
red0723@frontier.com
This post has NOT been accepted by the mailing list yet.
In reply to this post by Eleo-3
Here is an idea to increment the stored element without storing 0 first. Hope this helps you, it worked for me.
storeElementIndexid=FirstNameTest${loopNo}
storeEval${loopNo} + 1loopNo
typeid=FirstNameTest${loopNo}
typeid=LastNameUser${loopNo}
typeid=UserNameTest.User${loopNo}@blah.com