Selenium Test - 在多个测试运行中保留会话
我有以下问题。当我开始我的selenium测试时,为了到达执行实际测试的部分,我需要启动浏览器,登录,做一些其他操作,然后就到了我想要测试的部分。
有没有办法只执行第一部分一次,让会话和浏览器保持打开状态。对于下一次测试运行,仅继续此会话,而不启动。
所以基本上我会进行一个测试初始化,并保持会话打开。 使用此初始化会话的其他测试每次都会重用该会话。
我正在使用 Java 和 Selenium RC。
谢谢!
I have the following issue. When I start my selenium test, to get to the part where the actual test is performed, I need to start the browser, log in, do some other operations, and then it comes the part I want to test.
Isn't there a way to do the first part only once, leave the session and the browser open. And for a next test Run only continue this session, without starting up.
So basically I would have a test initializing, and leaving the session open.
And other tests which use this initialized session, reuse the session every time.
I am using Java, and Selenium RC.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在一定程度上取决于您的环境。我将 C# 与 Selenium RC(以及 NUnit 测试框架)结合使用。由于您使用 Java(大概还有 JUnit),它的工作方式是相同的。
JUnit 和 NUnit 都允许您指定在每个测试之前、每个测试之后、每个套件之前或每个套件之后执行的特殊代码。
在您的情况下,您希望提供在套件之前运行的代码(套件只是一个命名空间 (C#) 或类 (Java) 中所有测试用例的集合)。在 C# 中,我使用这样的代码 -
[TextFixtureSetUp ]
指令让 NUnit 将其识别为套件设置代码。Java 中的等效指定是使用
@BeforeClass
属性如我最近的文章使用 Selenium Sushi 进行 Web 测试:实用指南和工具集 非常关注 C#,但它可能为您提供一些可应用于 Java 工作的一般想法。
It depends a bit upon your environment. I use C# with Selenium RC (and therefore NUnit test framework). Since you use Java (and presumably JUnit) it works the same way.
Both JUnit and NUnit let you specify special code that executes before each test, after each test, before each suite, or after each suite.
In your case, you want to supply code to run before a suite (a suite simply being a collection of all your test cases in one namespace (C#) or class (Java)). In C# I use code like this--the
[TextFixtureSetUp]
directive is what lets NUnit recognize this as suite setup code.The equivalent designation in Java is to use the
@BeforeClass
attribute as inMy recent article Web Testing with Selenium Sushi: A Practical Guide and Toolset is very focused on C# but it may provide you with some general ideas that you could apply to your Java work.
我建议使用 testng 它允许您使用 java 注释进行预处理,例如仅在类或测试之前调用某些代码段套件分别使用@BeforeClass、@BeforeSuite。
在这里,您可以定义selenium服务器实例化,浏览器调用在测试套件类之前完成(还有许多其他选项可用),然后可以在后续测试方法中重用。
I would suggest using testng which lets you use java annotations for pre processing like invocation of certain piece of code only before class or test suite using @BeforeClass, @BeforeSuite respectively.
Herein you can define selenium server instantiation, browser invocation to be done either before a class of test suite (there are many other options also available) and then this could be reused in subsequent test methods.
一行:
您可以使用 Firefox 配置文件来实现这一点。
详细:
1. 手动登录您的 Firefox(如果您的网站有“记住我”选项,请使用它。否则应该没问题)
2. 转到 Firefox 菜单 >帮助>故障排除信息>配置文件文件夹(单击它)。
3.当您调用selenium webdriver(虽然不确定RC)时,使用
这种方式您将直接登录到您的帐户。这也更快,因为许多数据是从浏览器缓存中选取的,这与新的 Firefox 配置文件不同
In one line:
You can use firefox profile for that.
In Detail:
1. Login in your firefox manually (Use, Remember me option of your website if its there. else it should be ok)
2. Go to Firefox Menu > Help > Troubleshooting Information > Profile Folder (Click on it).
3. When you invoke you selenium webdriver (not sure about RC though), use this
This way you'll be directly logged in to your account. This also is faster as many data is picked from browser cache unlike fresh firefox profile