简体   繁体   English

每次编码的ui测试后失去焦点

[英]Losing focus after each coded ui test

I've got two testcases: 1. Click on the button. 我有两个测试用例:1.单击按钮。 After that Textbox appears. 之后出现文本框。 It shows till it has focus. 它显示直到有焦点为止。 2. Put some text in Textbox. 2.在文本框中输入一些文本。

Both testcases are in two separate TestMethods. 这两个测试用例都在两个单独的TestMethods中。 When first test passes, focus goes to visual studio. 当第一个测试通过时,重点将放在Visual Studio。 I guess it happens because of saving results in the studio in some way. 我想发生这种情况是因为以某种方式将结果保存在工作室中。 It works fine if both actions are in same TestMethod, but I need it to be in different tests. 如果两个动作都在相同的TestMethod中,则效果很好,但我需要在不同的测试中进行。 Is there any way to keep focus on application without going to VS? 有没有什么方法可以让您专注于应用程序而无需使用VS?

Here's that methods: 这是这些方法:

[TestMethod]
public void _01_Test_45040_AddProjectButtonClick()
{
    //ai.LeftPanelProjects.AddProjectButton.Click();
    WpfButton btnAddProj = CommonActions.GetControl<WpfButton>(app, "AddButton");
    btnAddProj.ClickField();
}

[TestMethod]
public void _02_Test_45041_TypeProjectName()
{
    WpfEdit txtProjName = CommonActions.GetControl<WpfEdit>(app, "NewProjectTextBox");
    txtProjName.Text = projectName;
}

UPD : This problem not appearing if using nUnit to run tests. UPD :如果使用nUnit运行测试,则不会出现此问题。 For some reason nUnit does not lose focus. 由于某些原因,nUnit不会失去焦点。 I've migrated all tests to it. 我已经将所有测试迁移到了它。

You can`t do that. 你不能那样做。 These are two distinct test cases. 这是两个不同的测试用例。 TestCleanup() and TestInitialize() are being executed between each test, therefore it will always return to VS. 在每个测试之间都将执行TestCleanup()和TestInitialize(),因此它将始终返回到VS。

Why don`t you just do that in your second test? 您为什么不在第二次考试中就这么做呢?

[TestMethod]
public void _02_Test_45041_TypeProjectName()
{
    WpfButton btnAddProj = CommonActions.GetControl<WpfButton>(app, "AddButton");
    WpfEdit txtProjName = CommonActions.GetControl<WpfEdit>(app, "NewProjectTextBox");
    btnAddProj.ClickField();        
    txtProjName.Text = projectName;
}

If you want to keep them in separate tests then you can call the second method from first. 如果要将它们保留在单独的测试中,则可以从第一个调用第二个方法。 It goes to VS because the first test method has finished its execution. 之所以进入VS,是因为第一个测试方法已经完成了执行。 You can do this. 你可以这样做。

[TestMethod]
public void _01_Test_45040_AddProjectButtonClick()
{
    //ai.LeftPanelProjects.AddProjectButton.Click();
    WpfButton btnAddProj = CommonActions.GetControl<WpfButton>(app, "AddButton");
    btnAddProj.ClickField();

     //calling the second method
    _02_Test_45041_TypeProjectName();
}

[TestMethod]
public void _02_Test_45041_TypeProjectName()
{
    WpfEdit txtProjName = CommonActions.GetControl<WpfEdit>(app, "NewProjectTextBox");
    txtProjName.Text = projectName;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM