3
votes

I have to automate a test-suite for a web application which let user connect and sync with their Dropbox account. I am using Java Selenium Webdriver.

Here I have created test classes like this.

Class1.java - Test case to check if connected to Internet.

Class2.java- Test case for sign in with Dropbox

Class3.java- Test case to verify if Dropbox folders are shown on web page.

Now these test classes are supposed to execute in this order.

But when I run the project as JUnit test, it executes these tests in some other order. I don't find any XML file so that I can specify order of execution of these classes.

I also have tried TestNG because I read Here that TestNG provides an attribute "preserve-order".

But It is not working. I don't have much experience with Selenium and Java Webdriver.

So any help would be appreciable.

Thanx in advance.

4

4 Answers

5
votes

Peter Niederwieser is right.

In addition you can set the order of the tests to run within the classes (Junit 4.11):

import org.junit.runners.MethodSorters;

import org.junit.FixMethodOrder;
import org.junit.Test;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SampleTest {

    @Test
    public void firstTest() {
        System.out.println("first");
    }

    @Test
    public void secondTest() {
        System.out.println("second");
    }
}
2
votes

Addition to Ittiel's post:

Instead of: @FixMethodOrder(MethodSorters.NAME_ASCENDING) You can use: @FixMethodOrder(MethodSorters.JVM)

This way, you don't have to play tricks with your test names. You only have to arrange your tests in the correct order.

This works fine for me. Thanks to Ittiel!

1
votes

You can use a JUnit test suite:

import org.junit.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({Class1.class, Class2.class, Class3.class})
public class DropboxWorkflow {}
0
votes

Try this

@Test(dataProvider = "Login", priority = 1)
public void login()
    {
     //code
    }

@Test(dataProvider = "Search", priority = 2)
public void search()
    {
     //code
    }