我只是想从运行 Selenium ( http://selenium.openqa.org ) 的人那里得到一些意见,我对 WaTiN 有很多经验,甚至为它编写了一个录音套件。我让它生成了一些结构良好的代码,但仅由我维护,看来我的公司几乎放弃了它。
如果您运行过 Selenium,您是否取得了很大的成功?
我将使用 .NET 3.5,Selenium 可以很好地配合它吗?
生成的代码是干净的还是只是所有交互的列表? ( http://blogs.conchango.com/richardgriffin/archive/2006/11/14/Testing-Design-Pattern-for-using-WATiR_2F00_N.aspx )
分布式测试套件的公平性如何?
对系统的任何其他提示或赞美将不胜感激!
最佳答案
如果您使用Selenium IDE生成代码,然后您只需获取 selenium 将执行的每个操作的列表。对我来说,Selenium IDE 是开始或进行快速“尝试和查看”测试的好方法。但是,当您考虑可维护性和更具可读性的代码时,您必须编写自己的代码。
实现良好 selenium 代码的一个好方法是使用 Page Object Pattern以代码代表您的导航流程的方式。这是我在 Coding Dojo Floripa 中看到的一个很好的例子(来自巴西):
public class GoogleTest {
private Selenium selenium;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox",
"http://www.google.com/webhp?hl=en");
selenium.start();
}
@Test
public void codingDojoShouldBeInFirstPageOfResults() {
GoogleHomePage home = new GoogleHomePage(selenium);
GoogleSearchResults searchResults = home.searchFor("coding dojo");
String firstEntry = searchResults.getResult(0);
assertEquals("Coding Dojo Wiki: FrontPage", firstEntry);
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
public class GoogleHomePage {
private final Selenium selenium;
public GoogleHomePage(Selenium selenium) {
this.selenium = selenium;
this.selenium.open("http://www.google.com/webhp?hl=en");
if (!"Google".equals(selenium.getTitle())) {
throw new IllegalStateException("Not the Google Home Page");
}
}
public GoogleSearchResults searchFor(String string) {
selenium.type("q", string);
selenium.click("btnG");
selenium.waitForPageToLoad("5000");
return new GoogleSearchResults(string, selenium);
}
}
public class GoogleSearchResults {
private final Selenium selenium;
public GoogleSearchResults(String string, Selenium selenium) {
this.selenium = selenium;
if (!(string + " - Google Search").equals(selenium.getTitle())) {
throw new IllegalStateException(
"This is not the Google Results Page");
}
}
public String getResult(int i) {
String nameXPath = "xpath=id('res')/div[1]/div[" + (i + 1) + "]/h2/a";
return selenium.getText(nameXPath);
}
}
希望有帮助
关于unit-testing - Selenium 批判,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/99876/