0

我现在很困惑,我不明白为什么我的代码不能按我的需要工作。事实上,每次有新的测试时,它都会关闭 firefox 并重新打开它。这让我的测试需要很长时间才能意识到......你能告诉我我做错了什么吗?

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();
    }
}

我试图将注释@BeforeClass 和@AfterClass 放在setUp() 和tearDown 之前,它不会改变任何东西。在每次测试之前都有一个 @Test 之前,但这根本没有帮助。我可以请你帮忙吗?=)

编辑:哦,我也在 setUp() 中尝试了 selenium.open(blablabla) 而不是直接在测试中,同样的问题,并没有改变任何事情。

4

1 回答 1

0

在不使用注释的情况下,setUp() 将在每次测试之前运行(即两次)。

这并不漂亮,但您可以创建一个初始测试(只运行一次)并将实例化从 setUp() 移到新的 test() 中。但是请记住,如果创建 selenium 实例失败,那么所有后续测试也将失败。不是很好 :)

于 2012-05-25T08:26:38.307 回答