繁体   English   中英

关于使用Eclipse和/或不使用Maven设置Selenium项目

[英]About Setting Up Selenium project with Eclipse and/or without Maven

我想尝试使用ChromeDriver或HTMLUnitDriver创建一个Selenium Webdriver项目,这是一个完整的初学者。 请告诉我是否正确。 我已经读过要设置一个Selenium Webdriver项目,可以通过在netbeans中创建一个Maven项目并配置pom.xml文件来下载依赖项来做到这一点。 但是我现在真的不知道从哪里开始,或者如何正确配置Maven。

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

大! 很高兴看到Selenium WebDriver的另一个初学者! 我想推荐一个可以帮助您入门的项目。

您可以在此处下载它,或从github上签出, 在这里

它不需要使用Maven,但强烈建议使用某种依赖关系管理软件,如Maven的,蚂蚁或其他。 为什么? 因为说您有一个jar文件,并且您有多个贡献者。 这些贡献者将如何获得依赖? 他们需要自己下载jar吗? 以及您怎么知道他们下载了正确的版本?

该工具入门与-硒项目我只是给你的,是一个个人项目我一直在工作了一段时间,它有,我想,当我与硒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.

    }
}

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

Maven是强制性的吗?

没有! 不是

可以只下载库并包含它们吗?

对的,这是可能的!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM