太棒了!很高兴看到Selenium WebDriver的另一位初学者!我想推荐一个可以帮助您开始的项目。
你可以下载here,或者从GitHub检查出来,here
并不要求使用Maven,但它IS强烈建议使用某种依赖关系管理软件,如Maven的,蚂蚁或其他人。 为什么?因为说你有一个jar文件,并且你有多个贡献者。这些贡献者将如何获得依赖关系?他们会不得不自己下载这个罐子?你怎么知道他们下载了正确的版本?
的工具入门与 - 硒项目我只是给你的,是一个个人项目我一直在工作了一段时间,它有,我希望我有当我开始用的东西Selenium 2 WebDriver与Java。它还使用我在现实生活场景中使用真实回归系统实施的概念。
由于您是新手,您可能已经注意到各种使用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.
}
}
简单!没有?如果您确实需要此框架提供的帮助,我可以帮助您。
Ty为快速回答。 ;)我只需要将*“selenium-java-2.37.0.jar”*文件添加到类路径以及所有的/ lib jar文件中 – Jeflopo