在 HTTP 和 HTTPS 中运行自动化 Selenium 测试的良好模式?

发布于 2024-08-02 03:38:29 字数 142 浏览 3 评论 0原文

我有一组通过 HTTP 运行的 Selenium 测试 - 我想在 HTTPS 和 HTTP 下运行相同的测试,并尽可能减少重复。 我想其他人一定已经这样做了? 我使用 Java Selenium Remote Control - 但我可能可以翻译另一种语言的方法。

I have a set of Selenium tests which run via HTTP - I'd like to run the same tests under HTTPS aswell as HTTP with as little duplication as possible. I guess other people must already be doing this? I use the Java Selenium Remote Control - but I can probably translate a method from another language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-08-09 03:38:29

您可以将被测应用程序的 URL 作为参数传递给测试框架,或将其存储在属性文件中。 我这样做是为了在测试环境之间切换。

下面是一个从属性文件读取的简单示例:

protected void startSession() {
    Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox",
        applicationProperties.getProperty("application.url"));
}

以及使用参数的示例(我使用 TestNG 来实现此目的):

在 TestNG 套件 XML 文件中添加参数:

<parameter name="appURL" value="http://www.example.com/" />

创建 Selenium 实例时使用该参数:

@BeforeMethod(alwaysRun = true)
@Parameters({"appURL"})
protected void startSession(String appURL) {
    Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", appURL);
}

You could pass the URL of the application under test to your test framework as a parameter, or store it in a properties file. I do this to switch between test environments.

Below is a simple example of reading from a properties file:

protected void startSession() {
    Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox",
        applicationProperties.getProperty("application.url"));
}

And an example of using a parameter (I use TestNG for this):

Add parameters in the TestNG suite XML file:

<parameter name="appURL" value="http://www.example.com/" />

Use the parameter when you create a Selenium instance:

@BeforeMethod(alwaysRun = true)
@Parameters({"appURL"})
protected void startSession(String appURL) {
    Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", appURL);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文