1

我正在使用 Selenium 进行测试,我们在 HTML 文件中编写测试用例并用它们制作测试套件,我们的要求是编写足够健壮的测试用例,以便根据测试环境改变自己。

为此,我不希望在 HTML 脚本本身中包含规范,例如要打开的 URL、要在屏幕上搜索的文本等。

我遇到了一个很好的基于用户的命令扩展:storeGlobal 虽然这个命令确实对我有很大帮助,但我想要的是让测试人员能够只更改属性文件,并且测试用例会从中获取值:

例如:在属性文件中:

startUrl = "http://www.google.com"

我知道由于浏览器的限制,javascript 通常无法访问文件系统,但是,我们使用 HTA 文件而不是 HTML 文件进行测试,是否可以通过它访问文件?如何 ?

4

3 回答 3

2

Try this: 1. Copy the user-extensions.js (storeGlobal command) from http://wiki.openqa.org/pages/viewpageattachments.action?pageId=284&metadataLink=true to your user-extensions.js

  1. Setup the user-extensions.js on your ide, close it and reopen your selenium ide again

  2. Create a new test case to store your properties and run that test case first Testscript1.html

    storeGlobal | http://www.example.com | site

    storeGlobal | myUsername | username

    storeGlobal | myPassword | password

  3. Create your other test cases and using the ${site}, ${username}, etc.. Testscript2.html

    open | ${site}/login.html

    type | id=username | ${username}

    type | id=password | ${password}

  4. Save TestSuite.html include testscrpt1.html and testscript2.html

  5. Run a quick test with Selenium ide and RC

I tested it today. And it works with IDE 1.9.1 and server selenium-server-standalone-2.25.0.jar.

If you find out is there any better way to setup a input properties file, please let me know. I am trying to run all the html selenium ide test suite in RC now. My email address is kamhor@yahoo.com. Thanks

于 2012-11-05T19:54:28.240 回答
1

根据http://www.c-point.com/javascript_tutorial/HTML_Applications.htm您可以完全访问文件系统。

于 2009-10-22T06:32:27.113 回答
1

我不确定从 Selenium IDE 中打开属性文件,但我可以建议一些可能的替代方案。

您可以使用 Selenium IDE 的store*命令来保存变量以供以后使用。如果您在套件的开头有一个设置了一些变量的测试,那么套件中的任何后续测试都可以使用它们。

例如,变量设置器测试可能如下所示:

storeExpression | http://www.example.com | site
storeExpression | myUsername | username
storeExpression | myPassword | password

那么套件中的以下测试可以使用这些变量:

open | ${site}/login.html
type | id=username | ${username}
type | id=password | ${password}

Alternatively, if you used Selenium RC you have a lot more options. You could have variables in your chosen client code, or use a .properties file like you first suggest.

于 2009-10-22T08:35:31.340 回答