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

2 posts, 0 answers
  1. hasantha
    hasantha avatar
    9 posts
    Member since:
    Jun 2014

    Posted 22 Jun 2014 Link to this post

    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. 
  2. Martin
    Admin
    Martin avatar
    811 posts

    Posted 23 Jun 2014 Link to this post

    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.
     
Back to Top