硒批评 [英] Selenium Critique

查看:24
本文介绍了硒批评的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想从运行 Selenium 的人那里得到一些意见(http://selenium.openqa.org) 我对 WaTiN 有很多经验,甚至为它写了一个录音套件.我让它生成了一些结构良好的代码,但只由我维护,我的公司似乎几乎放弃了它.

I just wanted some opinions from people that have run Selenium (http://selenium.openqa.org) I have had a lot of experience with WaTiN and even wrote a recording suite for it. I had it producing some well-structured code but being only maintained by me it seems my company all but abandoned it.

如果您运行过 selenium,您是否取得了很大的成功?

If you have run selenium have you had a lot of success?

我将使用 .NET 3.5,Selenium 可以很好地使用它吗?

I will be using .NET 3.5, does Selenium work well with it?

生成的代码是干净的还是只是所有交互的列表?(http:///blogs.conchango.com/richardgriffin/archive/2006/11/14/Testing-Design-Pattern-for-using-WATiR_2F00_N.aspx)

Is the code produced clean or simply a list of all the interaction? (http://blogs.conchango.com/richardgriffin/archive/2006/11/14/Testing-Design-Pattern-for-using-WATiR_2F00_N.aspx)

分布式测试套件的公平性如何?

How well does the distributed testing suite fair?

对系统的任何其他抱怨或赞美将不胜感激!

Any other gripes or compliments on the system would be greatly appreciated!

推荐答案

如果你使用的是 Selenium IDE 来生成代码,然后你会得到一个 selenium 将执行的每个动作的列表.对我来说,Selenium IDE 是开始或进行快速试看"测试的好方法.但是,当您考虑可维护性和更具可读性的代码时,您必须编写自己的代码.

If you are using Selenium IDE to generate code, then you just get a list of every action that selenium will execute. To me, Selenium IDE is a good way to start or do a fast "try and see" test. But, when you think about maintainability and more readable code, you must write your own code.

实现良好 selenium 代码的一个好方法是使用 页面对象模式 以代码代表您的导航流程的方式.这是我在 Coding Dojo Floripa(来自巴西):

A good way to achieve good selenium code is to use the Page Object Pattern in a way that the code represents your navigation flow. Here is a good example that I see in Coding Dojo Floripa (from Brazil):

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);
    }
}

希望有帮助

这篇关于硒批评的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆