【问题标题】:Selenium RC : Only one browser for all the tests?Selenium RC:所有测试只有一个浏览器?
【发布时间】:2012-05-25 07:40:42
【问题描述】:

我现在很困惑,我不明白为什么我的代码不能按我需要的那样工作。事实上,每次有新的测试时,它都会关闭 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) 而不是直接在测试中,同样的问题,不会改变任何事情。

【问题讨论】:

  • 不相关,但有什么理由让您仍在使用 Selenium RC - 已正式弃用。
  • 代码中的注释(@Something)在哪里?
  • @Arran 是的,webdriver 与 smartGWT 和 user-extensions.js 不兼容。简单的。弗兰克 我试过了,没用,把它们删掉了。但是我现在找到了解决方案,一切都很好:D
  • 如果你的解决方案成功了,为什么不把你的示例代码放在这个线程中呢?它将帮助任何需要面对类似问题的人更好地理解。

标签: java maven selenium selenium-rc


【解决方案1】:

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

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

【讨论】:

  • 不,我找到了解决方案。不要扩展 SeleneseTestCase。 SeleneseTestCase 覆盖每个注解,并在每次测试之前和之后执行 setUp 和 tearDown。它覆盖了 JUnit 4。所以我刚刚删除了它,声明了 setup 和 teardown static,添加了注释,现在可以正常工作了^^
猜你喜欢
  • 2018-07-22
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
  • 2011-11-27
  • 1970-01-01
  • 2011-02-19
  • 2010-11-10
  • 2013-06-24
相关资源
最近更新 更多