Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, windows and java based applications. Get your 30 day free trial.

Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com

JAVASCRIPT POP UP ISSUE

jrsreenivasjrsreenivas Members
edited November -1 in Sahi - Open Source
Hi Friends i am testing an application and i have encountered a problem suppose in a page where there are some text boxes and submit button when i wont enter any text in the required fields and enter the submit button validations pop up opens but i am not able to get the details using sahi ,i mean capturing the text on that pop and click of OK button ,Please let me know if any one has this issue.
Note:I am not able to view the source also when the pop up opens

Comments

  • narayannarayan Administrators
    Hi Sreenivas,

    Have a look at _lastAlert. http://sahi.co.in/w/_lastalert

    Regards,
    Narayan
  • narayannarayan Administrators
    Hi Sreenivas,

    There is no need to change the source code of the application!

    When you click a button which throws an alert, you can access the alert message in your Sahi script using _lastAlert().

    You can then assert your alert message.

    Is this what you want, or are we looking at two different problems?

    Regards,
    Narayan
  • _assertEqual("- First Name is required",_lastAlert());
    Assertion Failed.
    Expected:[- First Name is required]
    Actual:[- First Name is required
    - Last Name is required
    - Username is required
    - Password is required
    - E-mail Address is required
    - Confirm Password is required
    - Task Group is required
    ] at Jun 10, 2010 3:46:21 PM
  • _assertEqual("- First Name is required",_lastAlert());
    Assertion Failed.
    Expected:[- First Name is required]
    Actual:[- First Name is required
    - Last Name is required
    - Username is required
    - Password must be between 5-16 characters
    - E-mail Address is required
    - Confirm Password is required
    - Task Group is required
    ] at Jun 10, 2010 3:49:29 PM
  • how should i solve above problem
  • narayannarayan Administrators
    You will need to look at the indexOf your substring in the alerted message.
    _log(_lastAlert());
    _assertTrue(_lastAlert().indexOf("- First Name is required") != -1);
    
  • Hi Narayan when i enter all the fields correctly in the text boxes and submit the form, the log is stored as null and when i compare for the log value and check the condition i encounter the problem again. i am pasting the code of the script


    _setValue(_textbox("strFirstName"), "test");
    _setValue(_textbox("strLastName"), "user6");
    _setValue(_textbox("strEmailAddress"), "testuser6@sykes.com");
    _setSelected(_select("cboLanguage"), "Portuguese");
    _setValue(_textbox("strUsername"), "testuser6");
    _setValue(_password("strPassword"), "passowrd1!");
    _setValue(_password("strConfirmPassword"), "passowrd1!");
    _setSelected(_select("ddlTaskGroup"), "Administrator");


    _click(_submit("Create »"));



    //_assertNotEqual("- First Name is required",_lastAlert());

    //_log(_lastAlert());

    if(_log(_lastAlert()) != null)
    {
    _assertNotTrue(_lastAlert().indexOf("- First Name is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Last Name is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Username is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Password is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- E-mail Address is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Confirm Password is required") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Task Group is required ") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Password must be between 5-16 characters ") != -1);
    _assertNotTrue(_lastAlert().indexOf("- Value must be the same as Password value ") != -1);
    }

    /*

    if(_log(_lastAlert()) != null)
    {
    _assertTrue(_lastAlert().indexOf("- First Name is required") != -1);
    _assertTrue(_lastAlert().indexOf("- Last Name is required") != -1);
    _assertTrue(_lastAlert().indexOf("- Username is required") != -1);
    _assertTrue(_lastAlert().indexOf("- Password is required") != -1);
    _assertTrue(_lastAlert().indexOf("- E-mail Address is required") != -1);
    _assertTrue(_lastAlert().indexOf("- Confirm Password is required") != -1);
    _assertTrue(_lastAlert().indexOf("- Task Group is required ") != -1);
    _assertTrue(_lastAlert().indexOf("- Password must be between 5-16 characters ") != -1);
    _assertTrue(_lastAlert().indexOf("- Value must be the same as Password value ") != -1);
    }

    */
  • i tried with assertTrue and _assertNotTrue but bothe gives error
  • narayannarayan Administrators
    if(_log(_lastAlert()) != null) is incorrect.

    If you want to check if there was an alert, use:

    if (_condition(_lastAlert() != null))
  • girijagirija Members
    Hi Narayan,

    This is regarding popup window . While recording the popup window opens up prompting if i want to save the record(data). However there is a prob with playing it back. The pop up window does not show up even when the playback is successful. Here is the sample of the script:

    _click(_submit("Add"));
    _setValue(_textbox("addAddressDesc"), "'test2'");
    _expectConfirm("Are you sure you want to save this record?", true);( this is not shown while playin it back)
    _click(_submit("Save"));

    Please let me know what needs to be done . Thank you .

    Sincerely,
    Girija
  • narayannarayan Administrators
    Hi Girija,

    The popup will not be visible during playback even though the behaviour will be as if the dialog did appear. You can check this by setting _expectConfirm value to false,
    _expectConfirm("Are you sure you want to save this record?", false);
    and see how it works.

    You can also check if a confirm dialog appeared by asserting for it.

    _assertEqual("Are you sure you want to save this record?", _lastConfirm());

    Regards,
    Narayan
  • girijagirija Members
    Hi Narayan,

    Thanks for replying. I tried with

    _expectConfirm("Are you sure you want to save this record?", false); and

    _assertEqual("Are you sure you want to save this record?", _lastConfirm());


    There is no change in playback. It plays back as it was with

    _expectConfirm("Are you sure you want to save this record?", true);

    is there somethin else to check if the dialogue box appears..?

    Girija
  • Hi Narayan,

    Thanks for such a wonderful tool.

    I am new to automated testing tools, and I got stuck-up at confirm dialog handling.

    I also came across the same problem as Girija has mentioned in her latest post.

    I tried by clearing the last confirm info. But no change in behavior.

    Can you please guide in this case.

    Regards,
    Anand
  • Hi spark164,

    Could you please let me know where exactly you are facing issue using confirm dialog.

    As Narayan has mentioned, the popup will not be visible during playback even though the behaviour will be as if the dialog did appear.

    If you want to check if the dialogue box appeared then you can use: _lastConfirm().

    Usage:

    var $text = _lastConfirm();
    _alert($text);

    Also, have a look at: http://sahi.co.in/w/_expectConfirm

    Regards
    Sumitra
  • Thanks Sumitra,

    I used _lastConfirm(); , _clearLastConfirm(); and it is working fine.

    The problem is with _expectConfirm();

    1. The message displayed on confirm dialog as mentioned below;

    <Message string>
    <Blank line>
    <Blank line>
    <Message string>
    <OK> <Cancel>

    2. The confirmation dialog message string in web page source is as mentioned below;
    <Message string>\r\r<Message string>

    3. The string captured during record is as mentioned below;
    <Message string> <Message string>

    4. I tried using regular expression but did not worked;
    /.*<Message string>.*<Message string>.*/

    Not sure, but I think the failure of _expectConfirm() is due to the difference in point no 2 and point no 3.

    Can you please guide me to resolve this issue.
  • Hi spark164,

    Could you please share the URL or point us to an application with the same issue.

    Regards
    Sumitra
  • Hi Sumitra,

    This site is not accessible from outside.

    Below is a code snippet :

    <input type="button" name="submitDeleteButton" tabindex="2" value="Delete" onclick="return (confirm('When you delete the category, all of subordinate\rcategory and category/products are deleted! \r\rDelete OK?')?doSelfSubmit('_self','/admin/BSCXXXXXXXX.do'):false);" id="submitDeleteButton" class="button_normal">

    Regards,
    Anand
  • Hi spark164,

    Use:

    _expectConfirm("When you delete the category, all of subordinate\rcategory and category/products are deleted! \r\rDelete OK?", false);

    Check if this solves your issue.

    Regards
    Sumitra
  • @girija said:
    Hi Narayan,

    This is regarding popup window . While recording the popup window opens up prompting if i want to save the record(data). However there is a prob with playing it back. The pop up window does not show up even when the playback is successful. Here is the sample of the script:

    Hi guys
    It seems like the script is encountering an issue during playback when dealing with a popup window that prompts the user to save data. The problem description is clear, but it would be helpful to include more details about the testing environment, the automation tool or language being used, and any specific error messages or code snippets related to the issue.

Sign In or Register to comment.