Pops
Pops

Reputation: 30828

Is there a way to make actions optional in Selenium IDE?

This is a bit of a newbie question, but... is there a way to make actions optional in Selenium IDE? I'll provide a use case.

In the app I'm testing, users see a "hey, you're agreeing to the ToS by logging on"-type modal window at the beginning of each session. They have to click OK to continue, and they don't see the window again until the next session.

Based on what I've seen so far, I need to have one test suite for the first test each day, and a second test suite for all the others. The second suite is exactly the same except that it doesn't have the "click okay to dismiss the initial modal window" step. Alternatively, I could just remember that my first run of the test each day will fail, and that I have to run the test again.

Both of those "solutions" seem unnecessarily awkward. Can I just make the click command optional?

Upvotes: 4

Views: 8231

Answers (6)

Greg
Greg

Reputation: 1

Use http://wiki.openqa.org/display/SEL/flowControl addon. Make something like this :

1.storeElementPresent | //button[@name="cookie_law_accept"] | cookie_law
2.goToIf | storedVars['cookie_law']!=true | end
3.click | //button[@name="cookie_law_accept"]
4.label | end

Explain: 1.If element is present it will be stored as a "cookie_law" with value "true" 2.If cookie_law is not "true" - go to label "end" - other way go to next step 3.Click to cookie accept button (only when itsenter code herepresent because it its not - you go to "end" label and you skip this command) 4.You go here if there is no cookie law button :)

Upvotes: 0

Eric Schwa Pivnik
Eric Schwa Pivnik

Reputation: 1

Another extremely useful flow control add-on for the IDE is SelBlocks

It will give you the ability to use: if/else/for/foreach/while and even a way to read variables from an XML file.

Upvotes: 0

Patrick64
Patrick64

Reputation: 440

Create a javascript file called user-extensions.js with the below code. Then go into the Selenium IDE Options dialog and select your user-extensions.js file, restart Selenium and you'll be able to choose TryClick which will work the same as Click but suppress any errors.

Selenium.prototype.doTryClick = function(locator) {
    try {
        return Selenium.prototype.doClick.call(this,locator);
    } catch(err) { return null; }   
};

Upvotes: 4

grepit
grepit

Reputation: 22392

As aj.esler pointed it out Selenium ID Flow control is a good solution that has worked for me. Here is the Firefox add on I use the gotoif, here is an example about how you can use it. When skip value is 1 then it will go to the label=jump line and will not execute everything from gotoif like to label=jump . enter image description here

Upvotes: 1

AI Snoek
AI Snoek

Reputation: 2526

Perhaps overdue, but for future searchers.

You could use the if and endIf statements within the IDE.

Upvotes: 3

aj.esler
aj.esler

Reputation: 931

If you are using cookies to decide whether to hide the ToS dialog, you could check that a certain cookie is set and if so, skip the click.

I haven't used the selenium IDE much, but I think doing the check would be much easier if you are using a programming language. I am not sure how to do it in HTML tests.

If you are using HTML, you could have a look for Selenium IDE Flow Control and see if that can do what you need. I haven't used this myself, but if looks like it supports if statements. You could use verifyCookie to check if the cookie exists.

Hope that helps.

Upvotes: 1

Related Questions