我正在尝试做一些编码的UI测试,以帮助在我工作的公司进行一些手动测试的自动化。 我对Visual Studio的CUIT部分相当陌生,但我觉得我正在搞清楚。 但是,我在测试线程在其他测试运行之前关闭时遇到问题。
所以我想让这个测试完全自动化,因为所有开发人员需要做的就是单击“全部运行”,它们都会自动运行。 我遇到的问题是,第一次测试需要启动Internet Explorer,访问网站并登录到网站。 其余的测试基于登录到系统。 但是,在第一次测试之后,浏览器关闭并且随着第一种测试方法一起被杀死。
任何建议,这将是伟大的,我已经在网上搜索一些答案,但很多是非常老版本的视觉工作室,我试过的人不工作。
谢谢。
编辑:因此,在每个类内部都可以说“CodedUITest1.cs”,我可以在每个[Test Method]中使用同一个浏览器,就像我在那个类中所做的那样。 我遇到的问题是,如果我想要一个不同的测试类来测试不同的功能,“CodedUITest2.cs”,当第一个类完成测试时,浏览器将关闭。
I am trying to make some coded UI tests to help automate some of the manual testing at the company I work at. I am pretty new to the CUIT part of visual studio, but I feel like I am figuring it out. However I am having an issue with the testing thread being closed before the other tests run.
So I want to make this testing fully automated, as in, all the developer will need to do is to click "Run all" and they will all run automatically. The problem that I am having is that the very first test needs to launch Internet Explorer, go to a website, and log into the website. The rest of the tests are based off of being logged into the system. However, after the first test, the browser closes and gets killed along with the first test method.
Any advice on this would be great, I have searched online for some answers but a lot are for very old versions of visual studio, and the ones I have tried don't work.
Thank you.
Edit: So inside each class lets say "CodedUITest1.cs", I can use the same browser in each of the [Test Method]s that I have in that class (as someone suggested below). The issue I have is that if I want a different test class to test different functionality, "CodedUITest2.cs", the browser will close when the first class finishes its tests.
最满意答案
如果我正确理解你的问题,那么这段代码应该适合你:
BrowserWindow window; [TestMethod] public void Method1() { window = BrowserWindow.Launch(new Uri("http://www.bing.com")); window.CloseOnPlaybackCleanup = false; } [TestMethod] public void Method2() { window = BrowserWindow.Locate("Bing"); window.CloseOnPlaybackCleanup = false; } [TestMethod] public void Method3() { window = BrowserWindow.Locate("Bing"); }在阅读了这个问题的新信息之后,我已经测试了一下这些代码。 如果您想让浏览器在CodeUITes1.cs和CodedUITest2.cs之间保持打开状态,那么以下代码段可能会对您有所帮助。 它通过以下链接: https : //blogs.msdn.microsoft.com/devops/2012/11/08/coded-ui-test-why-does-application-close-after-each-test-in-视觉工作室-2012 /
文件:CodedUITest1.cs
public class CodedUITest1 { static BrowserWindow browserWindowInstance = null; public void LoadLocalHost() { if (browserWindowInstance == null) { browserWindowInstance = BrowserWindow.Launch(new System.Uri("YourWebSiteAddress")); browserWindowInstance.CloseOnPlaybackCleanup = false; browserWindowInstance.Maximized = !browserWindowInstance.Maximized; } else { browserWindowInstance.Maximized = !browserWindowInstance.Maximized; } } [TestMethod] public void CodedUITestMethod1() { LoadLocalHost(); // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. this.UIMap.ClickNewsAndEvents(); }CodedUITest2.cs文件:
[TestMethod] public void CodedUITestMethod2() { CodedUITest1 obj1 = new CodedUITest1(); obj1.LoadLocalHost(); // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. this.UIMap.ClickNewsPage(); }您可以添加更多的CodedUITest类。 只需在CodedUITest2类的代码示例中创建一个像obj1这样的新对象,并使用驻留在任何后续类的CodedUITest1.class中的LoadLocalHost()方法。 希望这能解决你的问题。
If I'm understanding your question correctly, then This code segment should work for you:
BrowserWindow window; [TestMethod] public void Method1() { window = BrowserWindow.Launch(new Uri("http://www.bing.com")); window.CloseOnPlaybackCleanup = false; } [TestMethod] public void Method2() { window = BrowserWindow.Locate("Bing"); window.CloseOnPlaybackCleanup = false; } [TestMethod] public void Method3() { window = BrowserWindow.Locate("Bing"); }After reading the new info of this question, I have tested the code a bit. If you want to keep the browser open between CodeUITes1.cs and CodedUITest2.cs, then the following code segment may help you. It is adopted from the following link: https://blogs.msdn.microsoft.com/devops/2012/11/08/coded-ui-test-why-does-application-close-after-each-test-in-visual-studio-2012/
File: CodedUITest1.cs
public class CodedUITest1 { static BrowserWindow browserWindowInstance = null; public void LoadLocalHost() { if (browserWindowInstance == null) { browserWindowInstance = BrowserWindow.Launch(new System.Uri("YourWebSiteAddress")); browserWindowInstance.CloseOnPlaybackCleanup = false; browserWindowInstance.Maximized = !browserWindowInstance.Maximized; } else { browserWindowInstance.Maximized = !browserWindowInstance.Maximized; } } [TestMethod] public void CodedUITestMethod1() { LoadLocalHost(); // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. this.UIMap.ClickNewsAndEvents(); }CodedUITest2.cs file:
[TestMethod] public void CodedUITestMethod2() { CodedUITest1 obj1 = new CodedUITest1(); obj1.LoadLocalHost(); // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. this.UIMap.ClickNewsPage(); }You can add more CodedUITest classes. Just create a new object like obj1 in the code sample of CodedUITest2 class, and use LoadLocalHost() method that resides in CodedUITest1.class from any subsequent classes. Hoping this will resolve your problem.
更多推荐
发布评论