Selenium 测试 - 在多个测试运行中保留会话 [英] Selenium Test - preserve session across multiple test runs

查看:85
本文介绍了Selenium 测试 - 在多个测试运行中保留会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.当我开始我的selenium测试时,为了到达进行实际测试的部分,我需要启动浏览器,登录,做一些其他的操作,然后才是我要测试的部分.

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.

我使用的是 Java 和 Selenium RC.

I am using Java, and Selenium RC.

谢谢!

推荐答案

这在一定程度上取决于您的环境.我将 C# 与 Selenium RC(以及 NUnit 测试框架)一起使用.由于您使用 Java(大概是 JUnit),它的工作方式相同.JUnit 和 NUnit 都允许您指定在每个测试之前、每个测试之后、每个套件之前或每个套件之后执行的特殊代码.

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.

在您的情况下,您希望提供在套件之前运行的代码(套件只是一个命名空间 (C#) 或类 (Java) 中所有测试用例的集合).在 C# 中,我使用这样的代码——[TextFixtureSetUp] 指令让 NUnit 将其识别为套件设置代码.

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.

   [TestFixtureSetUp]
    public void SetupTest()
    {
        selenium = Setup.StartSelenium();
        Setup.Login();
        Setup.Preliminaries();
    }

Java 中的等效名称是使用 @BeforeClass 属性如

The equivalent designation in Java is to use the @BeforeClass attribute as in

public class Example {
    @BeforeClass
    public static void onlyOnce() {
       ...
    }
 }

我最近的文章 使用 Selenium Sushi 进行 Web 测试:实用指南和工具集 非常关注 C#,但它可能会为您提供一些可应用于 Java 工作的一般性想法.

My 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.

这篇关于Selenium 测试 - 在多个测试运行中保留会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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