V1sh
V1sh

Reputation: 28

Tests for UI of a wizard application

I have been working on a Wizard application with Spring Web Flow and JSP/Tiles as View Technology. We have written UI Acceptance tests with webDriver/Selenium to test specific pages but have hit a showstopper.

Here is the current strategy ...

  1. Login once
  2. Go to 1st page, run all the tests on it
  3. Click next using Selenium
  4. Come to the 2nd page and run all the test on 2nd page

As you can see, Problem with this strategy is that the order of the tests matters (meaning you can not test 2nd page until you have not passed 1st page) If we were to test each page standalone, we would have to start from login screen everytime, and that means the time to run all the tests will increase EXPONENTIALLY.

Within a page, Which test is run first also matters (meaning by successfully clicking some link (if available), you should be able to see a pop-up)

Also with Junit testSuite we can only run ALL the tests within a class and not pick a few.

So my question is :

  1. Is there a way to pick up only few tests from a Test Class and run them in a given order?

Thanks for you help in advance ...

Upvotes: 0

Views: 639

Answers (3)

Gishu
Gishu

Reputation: 136633

How about making each group independent ?

  • Page1-suite
    • One-time-setup-for-suiet : Go to Page 1
    • Run all tests
  • Page2-suite
    • One-time-setup : Go to Page1, then Page2
    • Run all tests

This way you can tradeoff test-level independence for execution time. Now if I want to run one specific page2 test X, time = time for [Go to Page1, then Page2] + [TestX]

Seems like you're using JUnit, should work. We do this with NUnit for our acceptance tests. If you're writing Unit tests, however each test MUST be independent and fast.

Upvotes: 1

Pavel Janicek
Pavel Janicek

Reputation: 14748

You can also use PageObject approach where every page will be new object. Example

public class FirstPage{
private WebDriver driver; 
public FirstPage(){
  driver = new FirefoxDriver();
}

public WebDriver getDriver(){
return driver;
}

public void testSomething(){
// some test on first page
}

public SecondPage goToSecondPage(){
return new SecondPage(this)
}

}


public class SecondPage{
private FirstPage firstPage //that way you can access all variables in first page

public SecondPage(FirstPage first){
this.firstPage = first;
}

public void testSometingElse(){
firstPage.getDriver().findElement // thats how you access to the driver for instance
}
}

In nutshell - every WebElement of First page should be inside FirstPage class and so on. You can still access the driver via public calls. I use similar approach and that way I know where I am in test and am sure that whenever I use method of SecondPage class, I am on Second page.

Upvotes: 0

maguschen
maguschen

Reputation: 815

I don't know which test framework do you use for driving the Selenium test. If you employ TestNG, it may fit your requirement, for example

<test name="test_one" preserve-order="true">
    <classes>
        <class name="org.your.test.testclass">
            <methods>
                <include name="base_login" />
                <include name="navigate_page_one" />
                <include name="test_one" />
            </methods>
        </class>
    </classes>
</test>

<test name="test_two" preserve-order="true">
    <classes>
        <class name="org.your.test.testclass">
            <methods>
                <include name="base_login" />
                <include name="navigate_page_one" />
                <include name="test_two" />
            </methods>
        </class>
    </classes>
</test>

Meanwhile, you can achieve this by better organizing your test code. It has nothing to do with Selenium....

  • Extract each step into separate methods
  • Call those methods...

Upvotes: 0

Related Questions