如何运行在同一个浏览器实例的多个测试方法,而不将其关闭(C#,SeleniumWebDriverz NUnit的)? [英] How to run multiple test methods in same browser instance without closing it (C#, SeleniumWebDriverz NUnit)?

查看:848
本文介绍了如何运行在同一个浏览器实例的多个测试方法,而不将其关闭(C#,SeleniumWebDriverz NUnit的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我初学C#和硒。我想知道如果有可能,但不关闭它运行同一个浏览器实例的多个[TestMethod的] -s?

有关如Can_Change_Name_And_Title结束后,我要继续Can_Change_Profile_Picture。

  [TestMethod的]
    公共无效Can_Change_Name_And_Title()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewName(张三)SetNewTitle(新标题测试)ChangeNameTitle()。
    }    [测试方法]
    公共无效Can_Change_Profile_Picture()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewProfilePicture(Driver.BaseFilePath +Profile.png)ChangeProfilePicture()。
    }


解决方案

好了,所以这里是解决方案,我已经找到。相反的:

 使用Microsoft.VisualStudio.TestTools.UnitTesting;

我用:

 使用NUnit.Framework;

所以现在我有下一层次:

  [的TestFixture]
 [TestFixtureSetup] //这是我初始化我的webdriver新FirefoxDriver();
  [测试] //这是我的第一次测试
    公共无效Can_Change_Name_And_Title()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewName(张三)SetNewTitle(新标题测试)ChangeNameTitle()。
    }
  [测试] //这是我的第二次​​测试
    公共无效Can_Change_Profile_Picture()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewProfilePicture(Driver.BaseFilePath +Profile.png)ChangeProfilePicture()。
    }[TestFixtureTearDown] //这是我收我的司机

通过这种变化,我的浏览器会打开只有一次的TestFixture(或TestClass中如果使用使用Microsoft.VisualStudio.TestTools.UnitTesting;)和所有[测试]从夹具-s将在同一个浏览器实例中运行。所有测试完成后,浏览器将关闭。

希望这会帮助别人的未来人。问我,如果你需要额外的帮助。

I am beginner with c# and Selenium. I am wondering if it is possible to run multiple [TestMethod]-s in same browser instance without closing it?

For e.g. after "Can_Change_Name_And_Title" is finished, I want to continue with "Can_Change_Profile_Picture".

    [TestMethod]
    public void Can_Change_Name_And_Title()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewName("John Doe").SetNewTitle("New Title Test").ChangeNameTitle();
    }

    [TestMethod]
    public void Can_Change_Profile_Picture()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewProfilePicture(Driver.BaseFilePath + "Profile.png").ChangeProfilePicture();
    }

解决方案

Ok, so here is solution that I have found. Instead of:

 using Microsoft.VisualStudio.TestTools.UnitTesting;

I used:

 using NUnit.Framework;

So now I have next hierarchy:

[TestFixture]
 [TestFixtureSetup] // this is where I initialize my WebDriver " new FirefoxDriver(); "
  [Test] //this is my first test
    public void Can_Change_Name_And_Title()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewName("John Doe").SetNewTitle("New Title Test").ChangeNameTitle();
    }
  [Test] //this is my second test
    public void Can_Change_Profile_Picture()
    {
        SidebarNavigation.MyProfile.GoTo();
        ProfilePages.SetNewProfilePicture(Driver.BaseFilePath + "Profile.png").ChangeProfilePicture();
    }

[TestFixtureTearDown] // this is where I close my driver

With this changes, my browser will open only once for TestFixture (or TestClass if you use "using Microsoft.VisualStudio.TestTools.UnitTesting;") and all [Test]-s from that fixture will run in that same browser instance. After all tests are done, browser will close.

Hope this will help someone else in future. Ask me if you need additional help.

这篇关于如何运行在同一个浏览器实例的多个测试方法,而不将其关闭(C#,SeleniumWebDriverz NUnit的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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