Prueba CodedUI que no espera a que exista el control

I'm waiting for a control to exist, but the test fails before the button exists.

Da el error: The control is not available or not valid

El código que estoy usando es:

uIOKButton.WaitForControlExist(2000000);

// Click 'OK' button
Mouse.Click(uIOKButton, new Point(46, 19));

The time out, even though I have it set to 3 hours, times out after 30 mins. So the time out is not working the way it's supposed to. Is there anyway around it?

Is there anyway to stop it from failing other than increasing the timeout?

preguntado el 31 de julio de 12 a las 10:07

If you haven't already, check that the control really does exist and that it matches the search properties defined in the UIMap. -

I don not understand: Why do you not want to increase the timeout if it will take this long. And what do you mean with 'to stop it from failing'? Do you want a graceful exit, an exception handler or something? -

The question makes a lot more sense now. 30 minutes is the default test time out any chance that hasn't been changed in local.testsettings? -

@stoj Ya that has solved it thanks, sorry I didn't make it clearer. Thanks -

Ha it's nice when the solution is so simple. It is odd that the framework returns the misleading exception message. It has been a while since I had a test hit the time out but I seem to remember the normal time out exception being more useful. -

7 Respuestas

Lo hice así:

while (!uIItemComboBox.Exists)
        {
            System.Threading.Thread.Sleep(1000);
        }
uIItemComboBox.SelectedItem = this.MyComboBox.UIItemComboBoxSelectedItem;

I'm sure there are nicer ways, but it works.

Respondido 21 ago 12, 13:08

Thanks, but it was acutally the local.testsettings that was the problem. The default timeout was 30 mins so it would always time out then. No matter how much of a timeout you had in your code. - ELOvejaO

You can use while loop instead of if statement

El código se parece a esto

loopcyle = 1;
While(!uIOKButton.WaitForControlExist(2000) && loopcycle <=20)
{
    // Click 'OK' button
    Mouse.Click(uIOKButton, new Point(46, 19));
    loopcycle ++;
    break;
}

Thanks, Karthik KK

Respondido 01 ago 12, 03:08

Does this do the timeout then checks if the button exists or just keeps checking? - ELOvejaO

Your logic is flawed. After 2000 millisecond the WaitForControlExist returns false and the body of the loop is executed. Mouse.Click raises an exception because the button does not exist and the test will fail. Furthermore: why increment loopcycle while breaking out of the loop directly after it? And if you get rid of the break ánd the button exists (not raising an exception), then this script will press the button 19 times, raising another exception because the button does not exist anymore after it is pressed once. - Caos automatizado

I would suggest you to add a check like:

int count = 1;
while (btnExists() == false){ 
    if (count > 1000) {
        //fail test or say that btn is not available
     }
    count ++;
    wait (1);
}

You won't have to wait more than it's required. The test will go on as far as btn becomes available. But make sure to set "count" to have an exit point at some time, in case btn will never appear

Respondido 02 ago 12, 18:08

With the fail test area, I could just add the step of the test that comes after? Its not for this part of the test but a different part, that may also cause problems. - ELOvejaO

I guess, I don't really understand what you mean by "I could add the step of the test that comes after"? - mayordomo

Sorry, I mean that I could just add the next button to be pressed into that. Hope thats clearer - ELOvejaO

Your code is not correct. I think you meant a while loop instead of the first if declaración. - Caos automatizado

what you did originally is the correct way to do it. But after 30 minutes default test timeout pops up.

In your test solution under Solution Items folder find local.testsettings

Double click it, go to timeouts and remove the default timeout of 30 minutes.

Respondido 28 ago 12, 02:08

Quizás también quieras probar WaitForControlReady.

Respondido el 19 de enero de 17 a las 07:01

Utilice las Timeout attribute to make any particular test infinite. Also you can specify a certain time if you know that your test will run untill that time.

[Timeout(TestTimeout.Infinite)]

Respondido 04 Jul 18, 08:07

Use this attribute after [TestMethod] attribute. - saurabh keshari

Try this, before finding the control ID, did the trick for me but it will take some good amount of time. So if you want to load early may be look for the alternative.

BrowserWindow window = new BrowserWindow();
window.WaitForControlExist();

Respondido el 07 de Septiembre de 18 a las 18:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.