使用编码的UI在页面对象模式中实现多个TestMethods [英] Implementing multiple TestMethods in Page Object Pattern using Coded UI

查看:48
本文介绍了使用编码的UI在页面对象模式中实现多个TestMethods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我们正在跟踪页面对象模式.我们遇到的每个页面都有单独的类,每个类都包含用于控制这些页面的方法.

We are following page object pattern. We have individual classes for each page we come across and each class contains a method for the controls of those pages.

我们创建了两个TestMethods来分别测试两个不同的页面功能,就像两个测试用例一样.在TestMethods中,我们只是调用方法,然后应用一些断言.第一个TestMethod从一页开始(例如主页) 并在另一页上结束.第二种测试方法必须从第二页开始,依此类推.但是,当运行测试时将第二种测试方法作为重点时,我们将面临问题.

We have created two TestMethods to test two different page functionality separately just like two test cases. In TestMethods , we are simply calling the methods and then applying some assertions. The first TestMethod starts from one page (say Home page) and ends on another page. The second test method has to start from the second page and so on. However, we are facing issue when the second test method is in focus while running the tests.

在第二种测试方法中,我们将重用已经在TestMethod1中使用的方法.这次,我们得到了错误-

In second test method, we are reusing the methods which we have already used in TestMethod1. This time, we are getting the error -

" Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException:该控件不可用或无效.其他详细信息:未指定控件详细信息. ---> System.Runtime.InteropServices.InvalidComObjectException: 不能使用已与其基础RCW分开的COM对象."

"Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException: The control is not available or not valid. Additional Details: The control details were not specified. ---> System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used."

有没有一种方法可以继续执行而不会出现此错误?..如果您需要有关此信息的更多信息,请告诉我.

Is there a way to continue execution without this error?.. Please let me know if you need anymore info regarding the same.

感谢您的回复.

推荐答案

如果我正确理解了您的问题,那么您偶尔会在执行测试方法时遇到问题,因为该测试方法假定您在特定页面上网站上的内容,但情况并非总是如此吗?  看到问题的原因是您的测试 依赖于以特定顺序执行,但是没有保证执行测试的顺序.理想情况下,每种测试方法都可以独立于其他方法运行,但是我意识到这确实很耗时.  您 可以做一个大的有序测试,您可以在其中指定哪些测试以什么顺序执行.  如果您进行的测试数量较少,这可能没问题,但是如果您进行的测试数量很多,这可能有点 维护头痛.另外,有序测试的报告有点怪异.  您也可以使用 每个测试类中的类初始化方法,该类包含导航逻辑,可以在测试类中的任何测试方法执行之前到达正确的页面.  
If I understand your question correctly you occasionally have a problem executing a test method because the test method assumes you are on a particular page of your site but that is not always the case?  The reason you see a problem is that your tests rely on being executed in a particular order but there is no guaranteed order in which the tests will be executed.  Ideally every test method would be able to be run independent of other methods but I realize that can really get time consuming.  You could make one big ordered test where you specify which tests execute in what order.  This might be ok if you have a small number of tests but if you have many tests this is a bit of a maintenance headache.  Further the reporting of the ordered test is a little weird.  You could also use a class initialize method in each test class that contains the navigation logic to get to  the right page before any of the test methods in a test class execute.  


这篇关于使用编码的UI在页面对象模式中实现多个TestMethods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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