0

I'm quite stuck right now, I don't understand why my code doesn't work as I need to. The fact is that each time there is a new test, it closes firefox and reopens it. That makes my tests take ages to realise... Could you tell me what I'm doing wrong ?

public class SeleniumTestLoginEntry extends SeleneseTestCase {

    private String login="scLocator=//DynamicForm[ID=\"formulaire_login\"]/item[index=0||Class=TextItem]/element";
    private String passwd="scLocator=//DynamicForm[ID=\"formulaire_login\"]/item[index=1||Class=PasswordItem]/element";
    static public DefaultSelenium selenium;

    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4500, "*firefox", "http://localhost:9091/");
        selenium.start();
    }

    public void testFields() throws Exception {
        selenium.open("/agepro-prototype/login/Login.html");
        selenium.type(login, "Unlogin");
        selenium.type(passwd, "Unpassword");
        Assert.assertEquals("Unlogin", selenium.getValue(login));
        Assert.assertEquals("Unpassword", selenium.getValue(passwd));
        selenium.click("scLocator=//ImgButton[ID=\"bouton_login\"]/");
    }

    public void testSameWindow() throws Exception {
        selenium.open("/agepro-prototype/login/Login.html");
        selenium.type(login, "truc");
        Assert.assertEquals("truc", selenium.getValue(login));
    }

    public void tearDown() throws Exception {
        selenium.stop();
    }
}

I tried to put the annotations @BeforeClass and @AfterClass before the setUp() and tearDown, it doesn't change anything. Before there was an @Test before each test but this doesn't helped at all. May I ask you some help ? =)

Edit : Oh also I tried the selenium.open(blablabla) in the setUp() and not in the tests directly, same issue, doesn't change a thing.

Depado
  • 4,811
  • 3
  • 41
  • 63
  • 2
    Unrelated, but is there any reason why you are still using Selenium RC - which is officially deprecated. – Arran May 25 '12 at 08:09
  • Where are the annotations in your code (@Something)? – Franz Ebner May 25 '12 at 08:23
  • @Arran Yes, webdriver isn't compatible with smartGWT and user-extensions.js. Simple. Frank I tried them, didn't worked, removed them. But I found the solution now, everything is good :D – Depado May 25 '12 at 08:41
  • If you are successful with your solution, why don't you put your example code in this thread? It will help anyone who needs to faces similar issue, with better understanding. –  Sep 28 '12 at 04:30

1 Answers1

0

Without using annotations, setUp() is going to run before every test (ie, twice).

It's not pretty, but you can create an initial test (which only runs once) and move the instantiation out of setUp() into the new test(). Keep in mind, though, that if that fails to create your selenium instance, then all your subsequent tests will also fail. Not great :)

Denham Coote
  • 634
  • 8
  • 18
  • 1
    Nope, I found the solution. Do not extend SeleneseTestCase. SeleneseTestCase override every annotation and will execute setUp and tearDown before and after each test. It is overriding JUnit 4. So I just removed that, declared setup and teardown static, added annotations, and that works fine now ^^ – Depado May 25 '12 at 08:43