简体   繁体   中英

Losing focus after each coded ui test

I've got two testcases: 1. Click on the button. After that Textbox appears. It shows till it has focus. 2. Put some text in Textbox.

Both testcases are in two separate TestMethods. When first test passes, focus goes to 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. Is there any way to keep focus on application without going to 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. For some reason nUnit does not lose focus. 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.

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. 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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