cancel
Showing results for 
Search instead for 
Did you mean: 

Measure the time it takes for a button to become enabled

SOLVED
nedbacan
Contributor

Measure the time it takes for a button to become enabled

Can someone instruct me how I would measure the time it takes for a button to become enabled on the screen.  Should I use aqPerformance.Start()  or will it be better to use aqDateTime.Now() as a stopwatch when the option is selected and then get the time again once the button is enabled.  

 

If you can provide a sample it would be helpful to understand,  I read the usage of the methods but not too clear where I can place it in a script.  There are areas where I place the wait/pause method to slow down the script but will that affect the time the button from disable to enable state, and how will I present the time in the log file. 

 

Use Case scanario

1) User select an image

2) Right-click on the image - a menu appears

3) Select the option to enable "MA" - a dialog appears showing a disabled button.

4) User waits (approx 30 seconds) until the button becomes enabled.  - the current dialog shows the button enabled.

5) If the button takes longer than 30 seconds - the test case fails because it took longer than the requirement.

 

//Right Click on image
Aliases.browser.pageImagenet.vgSvgslice0.ClickR(347, 138);
//Click the option to turn on the button
Aliases.browser.pageImagenet.textnodeProcessingmovingaverage.Click(25, 13);
//Runs a script routine to pause until the button is enabled.
WaitForButton();
//Checks whether the 'contentText' property of the NameMapping.Sys.browser.pageExam.panelResult.panel object equals 'ON'
aqObject.CheckProperty(NameMapping.Sys.browser.pageExam.panelResult.panel, "contentText", cmpEqual, "MA\nClose\nON\n0");
//Run the next keyword test.

 

Thank you for your support.

3 ACCEPTED SOLUTIONS

Accepted Solutions
BenoitB
Community Hero

Re: Measure the time it takes for a button to become enabled

yes, i just forgot the () ..

Un sourire et ça repart

View solution in original post

AlexKaras
Community Hero

Re: Measure the time it takes for a button to become enabled

yes, i just forgot the () ..

Parenthesis are required for JavaScript only and until now JavaScript was not mentioned in any way... 😉

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

nedbacan
Contributor

Re: Measure the time it takes for a button to become enabled

Problem solved with aqPerformance.Value().

 

@AlexKaras and @BenoitBMy thanks to both of you and appreciation for your time.

View solution in original post

13 REPLIES 13
BenoitB
Community Hero

Re: Measure the time it takes for a button to become enabled

To wait for a property you can use .. WaitProperty 😁

 

To measure time, several methods exists, choose one.

aqPerformance is a good one.

 

So you can use this :

 

  aqPerformance.Start("DefaultCounter", false);
  if (!yourButtonObject.WaitProperty("Enabled", true, 30000))
    throw Error("TC Failed : Enabled button state not occured within 30s !");
  Log.Message("TC Success : Enabled button state occured in " + aqPerformance.Value + "ms");


 

Un sourire et ça repart

nedbacan
Contributor

Re: Measure the time it takes for a button to become enabled

Hello @BenoitB ,  I must be doing something wrong, can you check my code?

 

I placed your example in my script, which will be called by the main keyword, the script will be called when the option to show the button is clicked, once is clicked the following function is run, but it keeps choosing "throw error", I am sure it has not been 30 seconds, in other words, it fails right away.

 

function WaitForButton()
{

var button = Aliases.browser.pageExam.buttonOn

aqPerformance.Start("DefaultCounter", false);

if (button.WaitProperty("Enabled", true, 30000))

throw Error("TC Failed : Enabled button state not occured within 30s !");

Log.Message("TC Success : Enabled button state occured in " + aqPerformance.Value + "ms");

}

 

BenoitB
Community Hero

Re: Measure the time it takes for a button to become enabled

Does your button has the Enabled property ?

 

The WaitProperty exit directly (what you have) when the property asked is missing :

Result Value

If the property achieves the specified value within the timeout, the method returns True. Otherwise, if the timeout elapses before the property achieves the specified value, the method returns False.

Also, False if the object does not have the specified property.

 

 

Put a breakpoint on line aqPerformance.Start("DefaultCounter", false); and when you come in, spy the button object.

 

Un sourire et ça repart

nedbacan
Contributor

Re: Measure the time it takes for a button to become enabled

@BenoitB , I attached the Spy object and button to show you what I have.  I am not sure what property I need.  It first shows "OFF"  and then I have to wait for it to turn to "ON". 

 

button.png    button2.pngSpy.png

buttonCont.png

BenoitB
Community Hero

Re: Measure the time it takes for a button to become enabled

try by using the property ObjectLabel and the value 'ON'

Un sourire et ça repart

AlexKaras
Community Hero

Re: Measure the time it takes for a button to become enabled

Hi,

 

var button = Aliases.browser.pageExam.buttonOn

Is it guaranteed that buttonOn exists at the moment when this line of code is executed?

If it is not guaranteed then try to replace the above line with

var button = Aliases.browser.pageExam.WaitAliasChild("buttonOn", 30000);

 

Does this help?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
nedbacan
Contributor

Re: Measure the time it takes for a button to become enabled

Hello

 

Yes, the button is displayed on the screen.  To test I manually called up the dialog with the button disabled, 

I then execute the script and wait for the button to become enabled but the script fails right away (takes the throw error path).   Tried WaitAliasChild and I get the same failure.

 

I added the script to the keyword test, when the option to open the dialog is called, the script is run so both (manually/automatically) 

 

Can you review the Object spy copied within this trail of messages, I also added how the button looks?

 

 

AlexKaras
Community Hero

Re: Measure the time it takes for a button to become enabled

Hi,

 


@nedbacan wrote:

it keeps choosing "throw error", I am sure it has not been 30 seconds, in other words, it fails right away.

 

function WaitForButton()
{

var button = Aliases.browser.pageExam.buttonOn

aqPerformance.Start("DefaultCounter", false);

if (button.WaitProperty("Enabled", true, 30000))

throw Error("TC Failed : Enabled button state not occured within 30s !");

Log.Message("TC Success : Enabled button state occured in " + aqPerformance.Value + "ms");

}

 


If you are talking about this code, then it works as expected:

-- The button becomes enabled within 30 seconds;

-- WaitProperty() returns 'true';

-- line with 'throw' statement is executed.

 

Code by Benoit was like this:

if (!button.WaitProperty("Enabled", true, 30000))

(note exclamation sign before 'button').

 

Does this help?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
nedbacan
Contributor

Re: Measure the time it takes for a button to become enabled

@AlexKaras 

Please excuse me for the missed exclamation mark.  I added the exclamation, and now it surpasses the throw error but the next statement issues "Cannot convert object to primitive value".

 

nedbacan_2-1611946170673.png

 

 

nedbacan_4-1611946281057.png

 

 

 

 

 

 

New Here?
Join us and watch the welcome video:
Announcements