"Wait for 'class' attribute 'Contains' value" fails with an unexpected error if the step converted to code

1 Answer 28 Views
Coded Steps
Daria
Top achievements
Rank 1
Daria asked on 09 Sep 2021, 08:48 AM

Hello.

I have a simple test (see Picture1).

I copied 2nd step "Wait for 'class' attribute 'Contains' value" and converted it to code (4th step).
In 2nd step, the test waits for condition 10 seconds and fails as expected. In 4th step, the test fails immediately with "Error: Unexpected error while waiting on condition" (see Picture2). I need to use waitings like this in coded steps.

Is it a bug? Or I do something wrong?

Test Studio Version 2021.2.809.0

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 13 Sep 2021, 02:59 PM

Hello Daria,

Thank you for contacting us with this scenario and for sharing details about the encountered behavior. 

I have to say that the converted Wait for attributes step does not work in the same way as the recorded one. This is because the recorded steps and the Test Studio UI manage elements in a slightly different way than on the Framework level. Once the step is converted to code, we only give guidance and references to the elements, but this implementation needs to be handled by the QA engineer or the developer of the test.

The issue comes from the wait part of the verification in the process of getting the attributes. Specifically when there is no such element on the page. There are two ways to go forward with this. 

  1. Use the originally recorded "Verify attribute contains" step and do not change its role to Wait step. For further customization of the test scenario, you can convert it to code and it will work as expected.
  2. If you need to wait for the element with specific attribute to appear in the DOM tree in a coded step, you can use the code sample below. It will wait for the target element to appear (in this case 30000 msec) and assert the specified attribute. Notice that I do not rely on elements from Pages and it is good practice to always initialize the elements that the code uses. The sample code uses an element from www.google.com page.
                var element =  this.ActiveBrowser.WaitForElement(30000, new string[]{ "tagname=a", "textcontent=Gmail"});
                Assert.IsNotNull(element);
                string attribute = element.GetAttribute("class").ToString();
                Assert.AreEqual("lorem ipsum", attribute);

Please check out the above suggestions and let me know if that solves the issue you were having. I remain available to continue our discussion and advise you further.

Regards,
Plamen Mitrev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Test Studio course! Check it out at https://learn.telerik.com/.
Ivan
Top achievements
Rank 1
commented on 16 Sep 2021, 03:38 AM

Hello Plamen Mitrev,

can you say which checkInterval is used in

ActiveBrowser.WaitForElement(...

?

How can I configure checkInterval for that?

Plamen Mitrev
Telerik team
commented on 17 Sep 2021, 11:04 AM

Hello Ivan,

WaitForElemen() uses 500 msec check interval to look for the target element. This can be configured in the properties of Wait for Exists steps, but can not be changed in the coded step. Hope this answers you questions.

Tags
Coded Steps
Asked by
Daria
Top achievements
Rank 1
Answers by
Plamen Mitrev
Telerik team
Share this question
or