This is a migrated thread and some comments may be shown as answers.

Problem with clicking buttons(OK/Cancel) in javascript Popup Boxes

1 Answer 277 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
hasantha
Top achievements
Rank 1
hasantha asked on 22 Jun 2014, 05:00 AM
In our hybrid android application, we have native(not custom made) javascript confirm dialog boxes which pop up in certain GUIs. So how can we click the 'OK' or 'Cancel' Button in a confirm box without knowing the values of attributes of those buttons? Because Telerik Mobile Testing uses name-value pair properties that specify one or more attributes of the target element that we want to operate. 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 23 Jun 2014, 12:42 PM
Hello Hasantha,

Let me provide you with some more details about how Mobile Testing handles dialogs. Actually, we don't click any buttons when dialogs are triggered, because we don't have access to these dialogs at all. The dialogs are native and are out of the browser DOM tree, which automatically makes them unreachable for our framework as well. Instead of clicking on buttons, our framework overrides the native event handlers and simulates dialogs handling by attaching custom event handling code. All this happens when the web.dialogs.prepare function is called. So when the event fires (say calling a button that triggers an 'alert' dialog), the default alert handling code is already detached and no alert dialog is shown. Instead our custom handler code fires and we set the 'handled' property of the dialog object to true. We then return this object to the callback function parameter of the 'web.getstate' function call as shown here.

Here is a sample step code:

// Force an PROMPT dialog and verify its state.
step("HandleStatePrompt", function ()
{

       // Prepare for the dialog and show it by clicking a button that triggers it. (This button should implement custom logic that triggers the dialog.)
        return [web.dialogs.prepare(web.dialogs.PROMPT, { dialogResult: 'prompt text' }),
                   web.click({ id: 'promptBtn' }),
                   // Check the state of the handled dialog
                   web.dialogs.getState(function (state)
                   {
                          assert(state[web.dialogs.PROMPT][0].handled).equals(true);      
                   })
         ];
});


Regards,
Martin
Telerik

 
Test your Android and iOS apps against any device or browser with Telerik Mobile Testing. Part of the Telerik Platform.
 
Tags
General Discussions
Asked by
hasantha
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or