ELSheepO
ELSheepO

Reputation: 305

CodedUI test not waiting for control to exist

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

It gives the error: The control is not available or not valid

The code I'm using is:

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?

Upvotes: 2

Views: 11493

Answers (7)

Krish
Krish

Reputation: 688

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();

Upvotes: 0

saurabh keshari
saurabh keshari

Reputation: 1

Use 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)]

Upvotes: 0

Hagashen Naidu
Hagashen Naidu

Reputation: 128

You might also want to try WaitForControlReady.

Upvotes: 0

Stas Sh
Stas Sh

Reputation: 676

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.

Upvotes: 0

i know nothing
i know nothing

Reputation: 1002

I did it like this:

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

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

Upvotes: 1

buxter
buxter

Reputation: 593

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

Upvotes: 0

Karthik KK
Karthik KK

Reputation: 38

You can use while loop instead of if statement

The code looks something like this

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

Thanks, Karthik KK

Upvotes: 0

Related Questions