2

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?

8
  • If you haven't already, check that the control really does exist and that it matches the search properties defined in the UIMap. Commented Jul 31, 2012 at 14:33
  • 1
    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? Commented Aug 2, 2012 at 14:07
  • 3
    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? Commented Aug 8, 2012 at 12:02
  • 1
    @stoj Ya that has solved it thanks, sorry I didn't make it clearer. Thanks Commented Aug 8, 2012 at 13:29
  • 1
    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. Commented Aug 8, 2012 at 15:56

7 Answers 7

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

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

2 Comments

Does this do the timeout then checks if the button exists or just keeps checking?
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.
0

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

4 Comments

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.
I guess, I don't really understand what you mean by "I could add the step of the test that comes after"?
Sorry, I mean that I could just add the next button to be pressed into that. Hope thats clearer
Your code is not correct. I think you meant a while loop instead of the first if statement.
0

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.

Comments

0

You might also want to try WaitForControlReady.

Comments

0

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

1 Comment

Use this attribute after [TestMethod] attribute.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.