[CodedUI]在orderedtest的多个测试方法中保留浏览器实例 [英] [CodedUI] Preserving browser instance across multiple test methods part of an orderedtest

查看:75
本文介绍了[CodedUI]在orderedtest的多个测试方法中保留浏览器实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我已经根据自己的屏幕构建了编码后的ui测试解决方案.因此,所有与登录Web应用程序相对应的测试方法都在Login.cs下.处理主页的方法位于HomePage.cs下

I have structured my coded ui tests solution based on my screen. Thus all the test methods corresponding to login to web application are under Login.cs . methods that deal with home page are under HomePage.cs

我具有这种结构,可以使解决方案更易于管理.

I have this structure to make the solution more manageable.

现在,我必须保留用于登录的Web浏览器实例,以也可用于HomePage测试方法.否则,首页测试将失败,因为它们将无法引用Web浏览器实例.

now, i have to preserve the Web Browser instance that was used to login to be also available for HomePage test methods. otherwise the homepage tests will fail as they wont get reference to the web browser instance.

因此,我使用了Web浏览器的单例实例,该实例在登录时进行了初始化.

Thus i made use of singleton instance of Web Browser which is initialized during login.

我在我的orderedtest中包括了一种测试方法"LoginAsAdmin",在首页中包括了另一种测试方法"CreateTicket"

I included one test method 'LoginAsAdmin' in my orderedtest and other test method 'CreateTicket' from Homepage

据我所记得,有序测试使用反射加载测试方法.因此,一旦测试方法完成,所有参考文献都将发布.因此,由Login创建的单例实例不适用于Homepage.我认为这是可以预期的- 如果错误,请更正我的理解.

As, far as i remember, ordered test loads the test methods using reflections. thus once a test method is completed all the references are released. Hence the singleton instances created by Login is not available for HomePage. Which I think is expected -- please correct my understanding if wrong.

我知道以下替代方法

  1. 创建一个名为"CreateANewTicket"的新测试方法,并依次调用"Login"和"CreateTicket"方法.这样便保留了我的单例实例.
  2. 在"CreateTicket"方法的开头搜索浏览器实例.但是我会保留最后的选择,因为这要求在运行自动化测试时,只有一个浏览器实例对该应用程序处于活动状态.太多的限制.和 在每种测试方法开始之前,还需要附加代码.
  1. create a new test method as 'CreateANewTicket' and call 'Login' and 'CreateTicket' methods in sequence. Thus my singleton instance is preserved.
  2. Search for browser instance at the start of 'CreateTicket' method. However i would keep this at last option because this requires that only one browser instance to be active of that application when automated tests are running. too much restrictions. And also an additional code before each test method starts.

我想知道的是:可以使用有序测试来实现保留WebBrowser实例"的方案吗?有什么方法可以使我的WebBrowser实例也可用于orderedtest中的其他方法.

What I want to know is : Can the scenario 'of preserving WebBrowser instance' be achieved using ordered test ? Is there any way in which my WebBrowser instance is also available for other methods in an orderedtest.

-Rahul

推荐答案

嗨Rahul,

Hi Rahul,

感谢您在MSDN论坛中发帖.

Thank you for posting in MSDN forum.

根据您的问题,能否请您告诉我您是如何在编码的UI测试中创建测试方法的,是处理代码还是其他代码?

Based on your issue, could you please tell me how you create the test method in coded UI test, is it a handing code or other?

如果您要处理编码的UI测试代码,建议您尝试使用编码的UI测试构建器来记录此login.cs和HomePage.cs的UI操作.然后,WebBrowser实例将由生成的代码自动保留.

If you are handing code for coded UI test, I suggest you could try to use the coded UI test builder to record the UI actions for this login.cs and HomePage.cs. And the WebBrowser instance will be preserved automatically by the generated code.

因此,请参考以下步骤以从首页创建测试方法"LoginAsAdmin"和其他测试方法"CreateTicket"以用于您订购的测试

So please refer the following steps to create test method 'LoginAsAdmin' and other test method 'CreateTicket' from Homepage for your ordered test

第一步:您需要记录测试方法'LoginAsAdmin'并生成代码,然后

Step1: you will need to record the test method 'LoginAsAdmin' and you generated code, then the

WebBrowser实例将由生成的代码自动保留.

WebBrowser instance will be preserved automatically by the generated code.

步骤2:成功登录homepage.cs后,您可以尝试使用编码的UI测试生成器记录其他测试方法,然后生成代码.

Step2: after you login in the homepage.cs successfully, you could try to record other test methods using coded UI test builder and then generate code too.

第3步:建议您尝试播放这些编码的UI测试方法,然后检查这些操作是否可以成功播放.

Step3: I suggest you could try to playback these coded UI test methods and then check if these actions can be playback successfully.

第4步:如果这些编码的UI测试可以成功播放,我建议您可以尝试添加一个orderedtest,然后将这些测试方法添加到orderedtest中.

Step4: If these coded UI test can playback successfully, I suggest you could try to add a orderedtest and then add these test methods into the orderedtest.

注意:将这些测试方法添加到有序测试中时,需要确保从登录测试方法到首页测试方法的指定顺序符合您的测试方法.

Note: you will need to ensure your test methods according to the specified order from this login test method to this homepage test method when you are adding these test methods into the ordered test.

第5步:如果您没有按照从此登录测试方法到首页测试方法的顺序添加测试方法,建议您尝试更改测试顺序,如以下屏幕截图所示.

Step5: If you did not add the test methods according to the order from this login test method to this homepage test method, I suggest you could try change the test order like the following screen shot.

步骤6:在顺序测试中成功播放了这些测试方法后,建议您参考此UIMap.Designer.cs生成的编码来修改您的自定义代码,以进行编码的UI测试.

Step6: after you could playback these test method successfully in the ordered test, I suggest you could refer the generated coded from this UIMap.Designer.cs to modified your custom code for your coded UI test.

有关如何使用编码的UI测试生成器记录这些UI操作的更多信息,请参见:

For more information about how to use the coded UI test builder to record these UI actions, please see:

https://msdn.microsoft.com/en-us/library/dd286726.aspx?f = 255& MSPPError = -2147217396

最好的问候


这篇关于[CodedUI]在orderedtest的多个测试方法中保留浏览器实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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