2013-10-31 36 views
2

我是一个完全初学者,试图创建一个Selenium Webdriver项目,我认为使用ChromeDriver或HTMLUnitDriver。请告诉我如果我是正确的。我已经读过这个设置一个Selenium Webdriver项目,我可以通过在netbeans中创建一个Maven项目来完成该项目,并配置pom.xml文件以下载依赖关系。但是我不知道从哪里开始,或者目前如何正确配置Maven。关于使用Eclipse和/或不使用Maven设置Selenium项目

这让我想...... Maven是强制性的吗?要创建一个Selenium项目,我必须处理Maven?可以下载这些库(http://www.seleniumhq.org/download/)并将它们包含到“全局库”部分,然后将该库添加到项目“库”文件夹并使用import子句来使用一个包或另一个包?

回答

1

Maven是强制性的吗?

不!它不是

它可能只是下载库和包括它们?

是的,这是可能的!

Maven会做同样的事情! (简化)它会创建一个包含所有罐子的库并将其添加到您的项目中。

+0

Ty为快速回答。 ;)我只需要将*“selenium-java-2.37.0.jar”*文件添加到类路径以及所有的/ lib jar文件中 – Jeflopo

2

太棒了!很高兴看到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. 

    } 
} 

简单!没有?如果您确实需要此框架提供的帮助,我可以帮助您。

相关问题