太棒了很高兴看到另一个Selenium WebDriver初学者!我想推荐一个可以帮助你开始的项目。
你可以下载
here
,或从github查看,
here
不需要使用Maven,但它
是
强烈建议使用某种依赖性管理软件,如Maven、Ant或其他软件。
为什么?
因为假设您有一个jar文件,并且您有多个贡献者。这些贡献者将如何获得依赖性?他们必须自己下载罐子吗?你怎么知道他们下载了正确的版本?!
我刚刚给你的硒项目入门,是我已经做了一段时间的个人项目,它有我想要的东西
我
当我开始使用带有Java的Selenium 2 WebDriver时。它还使用了一个概念,我在现实生活中用现实生活中的回归系统实现了这个概念。
由于你是新手,你可能已经注意到了使用
driver.findElement(blah).click()
还有诸如此类丑陋的东西。这个框架特别通过提供方法(你可以流利地调用这些方法)将你从所有的困惑中抽象出来。
这个项目实际上
做
使用maven,您可以看到一个活跃的例子,说明maven如何与Java和jUnit一起工作,以提供一个不错的框架。
以下是框架中包含的一个示例-
/**
* This is a sample test that can get you started.
* <br><br>
* This test shows how you can use the concept of "method chaining" to create successful, and independent tests, as well as the validations method that can get you started.
* @author ddavison
*
*/
@Config(url = "http://ddavison.github.io/tests/getting-started-with-selenium.htm", browser = Browser.FIREFOX) // You are able to specify a "base url" for your test, from which you will test. You may leave `browser` blank.
public class SampleFunctionalTest extends AutomationTest {
/**
* You are able to fire this test right up and see it in action. Right click the test() method, and click "Run As... jUnit test".
*
* The purpose of this is to show you how you can continue testing, just by taking the semi colon out, and continuing with your test.
*/
@Test
public void test() {
// click / validateAttribute
click(props.get("click"))
.validateAttribute(props.get("click"), "class", "success") // validate that the class indeed added.
// setText / validateText
.setText(By.id("setTextField"), "woot!")
.validateText(By.id("setTextField"), "woot!") // validates that it indeed set.
// check / uncheck
.check(By.id("checkbox"))
.validateChecked(By.id("checkbox")) // validate that it checked
.check(props.get("radio.2")) // remember that props come from <class name>.properties, and are always CSS selectors. (why use anything else, honestly.)
.validateUnchecked(props.get("radio.1")) // since radio 1 was selected by default, check the second one, then validate that the first radio is no longer checked.
// select from dropdowns.
.selectOptionByText(By.xpath("//select[@id='select']"), "Second") // just as a proof of concept that you can select on anything. But don't use xpath!!
.validateText(By.id("select"), "2") // validateText() will actually return the value="" attr of a dropdown, so that's why 2 works but "Second" will not.
.selectOptionByValue(By.cssSelector("select#select"), "3")
.validateText(props.get("select"), "3")
// frames
.switchToFrame("frame") // the id="frame"
.validatePresent(By.cssSelector("div#frame_content"))
// windows
.switchToWindow("Getting Started with Selenium") // switch back to the test window.
.click(By.linkText("Open a new tab / window"))
.waitForWindow("Google") // waits for the url. Can also be the you are expecting. :) (regex enabled too)
.setText(By.name("q"), "google!")
.closeWindow(); // we've closed google, and back on the getting started with selenium page.
}
}
易于理解的不如果你确实需要这个框架的帮助,我可以帮你。