多个实例的硒测试 [英] Selenium Testing with Multiple Instances

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

问题描述

我使用C#成功地使用XUnit构建了一个Selenium测试项目.如果我在一个类中单独运行所有测试,那么效果很好,但是当我尝试一次运行所有测试时,它失败了.罪魁祸首是测试的事实 并行运行,同时打开了多个浏览器.我的代码没有考虑到发生的事情的多实例性质.

Using C#, I successfully built a Selenium testing project using XUnit.  It worked fine if I was individually running all tests within one class but when I tried to run all tests at once it failed.  The culprit turned out to be the fact that tests were running in parallel, with multiple browsers opening up.  My code was not accounting for the multiple instance nature of what was occurring.

为解决此问题,我创建了一个实例"; TestFixture类中的属性"属性,然后将其传递给实例"每个执行浏览器操作的方法.它可以工作,但是看起来很笨拙.

To resolve this, I've created an "Instance" property in the TestFixture class and then passed "Instance" to every single method which performs a browser operation.  It works but it seems rather clumsy.

我很好奇这是正确的方法还是有更好的方法?

I'm curious if this is the right approach or is there a better way?

罗伯特

    public class TestFixture : IDisposable
    {
        public IWebDriver Instance { get; set; }

        #region Internal functionality - don't modify

        public TestFixture()
        {
            SetUp();
        }

        public void Dispose()
        {
            TearDown();
        }

        #endregion

        /// <summary>
        /// This is run once, before any tests are executed.
        /// </summary>
        private void SetUp()
        {
            Instance = Driver.Initialize();
            
            // Login
            Common.GoTo(Instance, "user/login");
            UserProfile user1 = new UserProfile(1);
            LoginPage.LogIn(Instance, user1);

            // TODO: Once "automation.testAdmin" user exists (with "IsAdmin = true") then
            //       add code here to ensure that Orgs/Repos/Users exist precisely in the
            //       'default' status they should.
        }

        /// <summary>
        /// This is run once, after all tests have completed.
        /// </summary>
        private void TearDown()
        {
            Driver.TearDown();
        }
    }

推荐答案

Robert Werner,您好,

Hi Robert Werner,

>>我很好奇这是正确的方法还是有更好的方法?

>>I'm curious if this is the right approach or is there a better way?

根据您的代码,我认为您的代码是实现问题的好方法.就像您说的那样,在同一个类下,VS中的测试方法可以并行运行.

According to your code, I think your code is a good way to implement your issue. Just as you said, under the same class, the test methods in VS could be run in parallel.

我还没有从硒设置中找到任何有用的信息来实现这一想法,所以我认为使用信号实例是一种好方法.

And I have not found any usefully information from selenium settings that could implement this idea, so I think using a signal instance is a good way.

此致

奥斯卡


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

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