Getting text from a Javascript alert popup

35 posts, 0 answers
  1. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 25 May 2010 Link to this post

    Is it possible to get the text from a javascript popup from the alert value property? I need to get a tracking number posted to a JS Alert and can't seem to find a way to get the value.
  2. Missing user
    Missing user avatar

    Posted 25 May 2010 Link to this post

    Hello Sam,

    Thanks for the post and question. So there really isn't a way to do what you describe using a built in feature in either QA or Dev edition.

    I'll log a feature request for this, but there are custom coded solutions we could offer in Dev Edition depending upon what browser(s) you would need this to run in and if you wanted to use a coded solution.

    Please reply back how you would like to proceed.

    Quick Edit: Sorry, forgot to mention the custom code solution should also work in QA edition. Please reply back if you'd like to continue working in code for this.

    Kind regards,
    Nelson Sin
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 26 May 2010 Link to this post

    Yes I would like to continue working in code to get this to work. I am using the QA Edition.
  4. Missing user
    Missing user avatar

    Posted 26 May 2010 Link to this post

    Hello again Sam,

    So for the QA edition, please:

    1) Extract the attached dll to the bin folder of your WebUI Test Project
    2) Add the dll as a reference to your test project in the UserSettings -> Script Options (See attached screentshot)
    3) Add a 'Script Step' to your test that will execute first.
    4) Click Class View and copy the following code.

    using System;
    using System.Collections.Generic;
    using System.Text;
      
    using ArtOfTest.Common.UnitTesting;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
    using ArtOfTest.WebAii.Design;
    using ArtOfTest.WebAii.Design.Execution;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.Silverlight;
    using ArtOfTest.WebAii.Silverlight.UI;
    using Telerik.WebAii.Controls.Html;
    using Telerik.WebAii.Controls.Xaml;
    using ArtOfTest.WebAii.Win32.Dialogs;
      
    namespace CustomHandlerQA
    {
      
        //
        // You can add custom execution steps by simply
        // adding a void function and decorating it with the [CodedStep] 
        // attribute to the test method. 
        // Those steps will automatically show up in the test steps on save.
        //
        // The BaseWebAiiTest exposes all key objects that you can use
        // to access the current testcase context. [i.e. ActiveBrowser, Find ..etc]
        //
        // Data driven tests can use the Data[columnIndex] or Data["columnName"] 
        // to access data for a specific data iteration.
        //
        // Example:
        //
        // [CodedStep("MyCustom Step Description")]
        // public void MyCustomStep()
        // {
        //        // Custom code goes here
        //      ActiveBrowser.NavigateTo("http://www.google.com");
        //
        //        // Or
        //        ActiveBrowser.NavigateTo(Data["url"]);
        // }
        //
              
      
        public class New_Test : BaseWebAiiTest
        {
            #region [ Dynamic Pages Reference ]
      
            private Pages _pages;
      
            /// <summary>
            /// Gets the Pages object that has references
            /// to all the elements, frames or regions
            /// in this project.
            /// </summary>
            public Pages Pages
            {
                get
                {
                    if (_pages == null)
                    {
                        _pages = new Pages(Manager.Current);
                    }
                    return _pages;
                }
            }
      
            #endregion
              
            // Add your test methods here...
          
            [CodedStep(@"Custom Confirm Handler Step'")]
            public void WebAiiTest1_CodedStep()
            {
                Manager.DialogMonitor.Dialogs[0].HandlerDelegate = CustomConfirm;
            }
      
            void CustomConfirm(IDialog dialog)
            {
                 Log.WriteLine(TelerikCustomHandler.HandleClass.HandleDialog(dialog.Window.Handle));     
                 dialog.HandlerDelegate = null;
            }
        }
    }

    Please note the Log.WriteLine(TelerikCustomHandler.HandleClass.HandleDialog(dialog.Window.Handle)); is where the Dialog Text  is returned, here it's being written to the test results log file.

    Also, the Manager.DialogMonitor.Dialogs[0] assumes the Dialog Handler you want to retrieve text from is the first one you added/recorded to the test. The index is 0 based, so please adjust this to the dialog handler you want to retrieve the text from.

    Please reply back if you have any questions on the above.

    Kind regards,
    Nelson
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 27 May 2010 Link to this post

    As soon as I add a script step and try to run the script I get an error "Compilation Failed" (I haven't added any custom code yet) In the log it says:

    --------------------------------------------------
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 1.aii.cs: Line 5: (CS0234) The type or namespace name 'UnitTesting' does not exist in the namespace 'ArtOfTest.Common' (are you missing an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 1.aii.cs: Line 14: (CS0246) The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 1.aii.cs: Line 15: (CS0246) The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 2.aii.cs: Line 1: (CS0246) The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 2.aii.cs: Line 2: (CS0246) The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 1.aii.cs: Line 51: (CS0246) The type or namespace name 'Pages' could not be found (are you missing a using directive or an assembly reference?)
    c:\Users\sdavis\Documents\WebUI Test Studio Projects\TestProject1\Sam Test 1.aii.cs: Line 58: (CS0246) The type or namespace name 'Pages' could not be found (are you missing a using directive or an assembly reference?)

    When I click on Class view, do I replace the code that is in the class with what you sent me? I still get the same error when I do that. When I remove the added script step, it still keeps failing with the failed compilation message.

     

  6. Missing user
    Missing user avatar

    Posted 27 May 2010 Link to this post

    Hello again Sam,

    Sorry about the late reply. Please check out the attached screenshot on how to check for and add dll references to you test project. Also, please note the versions of the following references of the ArtOfTest and Telerik dlls and verify they are 2010.1.5.18:

    ArtOfTest.Common
    ArtOfTest.WebAii
    ArtOfTest.WebAii.Design
    Telerik.WebAii.Controls.Html
    Telerik.WebAii.Controls.Xaml

    But regardless of whether the references are there and the version numbers, please try removing all of the ArtOfTest and Telerik references using the red 'X' button. Then, use the Add Reference button and re-add them from the following installation locations:

    \Program Files\Telerik\WebUI Test Studio 2010.1\Bin
    \Program Files\Telerik\WebUI Test Studio 2010.1\Bin\Translators

    If re-adding the references does not work, if you can please attach and send us the entire test project for us to check out on this end.

    Sincerely,
    Nelson
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 01 Jun 2010 Link to this post

    Thanks, I got it to work now.

  8. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 05 Aug 2010 Link to this post

    I need to do this using the the Developer Edition instead of the QA Edition. Do I use the same TelerikCustomHandler.dll that you sent me for the Developer Edition? I need to get the Text from a JS Alert popup. 
  9. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 05 Aug 2010 Link to this post

    Hello Sam Davis,

    Yes you can use the same DLL in both versions. In terms of recording and runnign tests the feature set between the QA edition and the Dev edition is virtually identical. The key difference is that QA edition has its own standalone IDE whereas the Dev edition is a plug-in to Visual Studio. Beyond that whatever can be done in one edition you should have no problems doing in the other. They even share most of the same source code base.

    Greetings,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Michael Flynn
    Michael Flynn avatar
    13 posts
    Member since:
    Apr 2010

    Posted 29 Sep 2010 Link to this post

    My script options is not enabled.  How do you enable the script options in the user settings?

    thanks.
  11. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 29 Sep 2010 Link to this post

    Hi Michael Flynn,

    I am sorry but I don't understand what "script options" you are referring to. Can you elaborate? Are you running into a problem? What error do you get?

    Best wishes,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Michael Flynn
    Michael Flynn avatar
    13 posts
    Member since:
    Apr 2010

    Posted 30 Sep 2010 Link to this post

    In your response to Sam, you say the following:

    Hello again Sam,

    So for the QA edition, please:

    1) Extract the attached dll to the bin folder of your WebUI Test Project
    2) Add the dll as a reference to your test project in the UserSettings -> Script Options (See attached screentshot)
    3) Add a 'Script Step' to your test that will execute first.
    4) Click Class View and copy the following code.

    I cannot execute #2 above because in my software, the UserSettings -> Script Options is disabled.  I would like to know how to enable this option so that I can follow the rest of the instructions.  I am using Telerik thru Visual Studio.

    Thanks,
    Mike
  13. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 30 Sep 2010 Link to this post

    Hello Michael,

    The Script Options is simply not needed in Visual Studio where you can add any needed assembly reference from the Visual Studio's Solution Explorer. Does that help?

    Sincerely yours,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Michael Flynn
    Michael Flynn avatar
    13 posts
    Member since:
    Apr 2010

    Posted 30 Sep 2010 Link to this post

    So after I do that, all of the other steps are the same then, right?

    Thanks for your help,
    Mike
  15. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 30 Sep 2010 Link to this post

    Hi Michael,

    You can add script step as in the QA Edition then add the sample code to the test step method you will get in the .cs file.

    Please let us know if you need further assistance.

    Regards,
    Konstantin Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Sam Davis
    Sam Davis avatar
    16 posts
    Member since:
    May 2010

    Posted 01 Oct 2010 Link to this post

    Thank you, I got this to work in C# but now I need to get it working using VB.NET. Can you show me how I would get the Text from a JS Popup using the Developer Edition in VB.

     

  17. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 04 Oct 2010 Link to this post

    Hi Sam Davis,

    Here is the same source code converted to VB.NET. Is that sufficient?

    Imports System.Collections.Generic
    Imports System.Text
     
    Imports ArtOfTest.Common.UnitTesting
    Imports ArtOfTest.WebAii.Core
    Imports ArtOfTest.WebAii.Controls.HtmlControls
    Imports ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts
    Imports ArtOfTest.WebAii.Design
    Imports ArtOfTest.WebAii.Design.Execution
    Imports ArtOfTest.WebAii.ObjectModel
    Imports ArtOfTest.WebAii.Silverlight
    Imports ArtOfTest.WebAii.Silverlight.UI
    Imports Telerik.WebAii.Controls.Html
    Imports Telerik.WebAii.Controls.Xaml
    Imports ArtOfTest.WebAii.Win32.Dialogs
     
    Namespace CustomHandlerQA
     
        
        ' You can add custom execution steps by simply 
        ' adding a void function and decorating it with the [CodedStep]  
        ' attribute to the test method.  
     
        ' Those steps will automatically show up in the test steps on save. 
        
        ' The BaseWebAiiTest exposes all key objects that you can use 
        ' to access the current testcase context. [i.e. ActiveBrowser, Find ..etc] 
        
        ' Data driven tests can use the Data[columnIndex] or Data["columnName"]  
        ' to access data for a specific data iteration. 
        
        ' Example: 
        
        ' [CodedStep("MyCustom Step Description")] 
        ' public void MyCustomStep() 
        ' { 
        '       // Custom code goes here 
        '     ActiveBrowser.NavigateTo("http://www.google.com"); 
        
        '       // Or 
        '       ActiveBrowser.NavigateTo(Data["url"]); 
        ' } 
        
     
        Public Class New_Test
            Inherits BaseWebAiiTest
     
            #Region "[ Dynamic Pages Reference ]"
     
            Private _pages As Pages
     
            ''' <summary> 
            ''' Gets the Pages object that has references 
            ''' to all the elements, frames or regions 
            ''' in this project. 
            ''' </summary> 
     
            Public ReadOnly Property Pages() As Pages
                Get
                    If _pages Is Nothing Then
                        _pages = New Pages(Manager.Current)
                    End If
     
                    Return _pages
                End Get
            End Property
     
            #End Region
     
            ' Add your test methods here... 
     
            <CodedStep("Custom Confirm Handler Step'")> _
            Public Sub WebAiiTest1_CodedStep()
                Manager.DialogMonitor.Dialogs(0).HandlerDelegate = AddressOf CustomConfirm
            End Sub
     
            Private Sub CustomConfirm(dialog As IDialog)
                Log.WriteLine(TelerikCustomHandler.HandleClass.HandleDialog(dialog.Window.Handle))
                dialog.HandlerDelegate = Nothing
            End Sub
        End Class
    End Namespace

    All the best,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Michael Flynn
    Michael Flynn avatar
    13 posts
    Member since:
    Apr 2010

    Posted 04 Oct 2010 Link to this post

    thanks for the help on this.  Sam and I are working on the same issue.  The problem that has us stumped now is that after the text is retrieved from the popup, the next line in the code is not being executed.  This line is the 'Handle Alert Dialog' line.  We get a failure that says the following:

    Timed out waiting '5000' msec. for dialog to be handled '1'
    InnerException:
    System.TimeoutException: Timed out waiting '5000' msec. for dialog to be handled '1'
       at ArtOfTest.WebAii.Win32.Dialogs.BaseDialog.WaitUntilHandled(Int32 handleCount, Int32 timeout, Boolean resetHandleCount)
       at ArtOfTest.WebAii.Design.IntrinsicTranslators.Descriptors.DialogHandlerDescriptor.Execute(Browser browser)
       at ArtOfTest.WebAii.Design.IntrinsicTranslators.Descriptors.DialogHandlerDescriptor.Execute(IAutomationHost browser)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteStep()
    --------------------------------------------------
  19. Michael Flynn
    Michael Flynn avatar
    13 posts
    Member since:
    Apr 2010

    Posted 04 Oct 2010 Link to this post

    I figured it out, nevermind.  I tried using "handle generic dialog" instead and that works.

    Thanks for all your help on this whole thread.

    Mike
  20. Mark
    Mark avatar
    22 posts
    Member since:
    May 2011

    Posted 15 Jul 2011 Link to this post

    Hi Telerik Team,

    Is this feature included in the latest version of test studio?

    Thanks
  21. Mark
    Mark avatar
    22 posts
    Member since:
    May 2011

    Posted 15 Jul 2011 Link to this post

    Hi Telerik Team,

    Is this feature included in the latest version of test studio?

    Thanks
  22. Mark
    Mark avatar
    22 posts
    Member since:
    May 2011

    Posted 15 Jul 2011 Link to this post

    Hi Telerik Team,

    Is this feature included in the latest version of test studio?

    Thanks
  23. Mark
    Mark avatar
    22 posts
    Member since:
    May 2011

    Posted 15 Jul 2011 Link to this post

    Hi Telerik Team,

    Is this feature now included in the latest version?
  24. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 15 Jul 2011 Link to this post

    Hello Mark,

    Do you mean is it now possible to verify/extract text from a JavaScript Alert dialog without code through the UI? If so then the answer is no. The coded solution provided in this thread is a great work-around, however.

    Regards,
    Anthony
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?
  25. Saket
    Saket avatar
    22 posts
    Member since:
    Sep 2011

    Posted 23 Nov 2011 Link to this post

    Hi,

    Using the code posted in vs.net, what i am doing is throwing a application exception in the CustomConfirm method, however when the exception is fired it does not record it as an exception an fail the test as expected insted it gives the test result as Passed.
    here is the snippet

    public void SaveForm(string entityName_)
            {

                    ActiveBrowser.RefreshDomTree();
                    DialogMonitor.Start();
                    DialogMonitor.AddDialog(AlertDialog.CreateAlertDialog(Manager.ActiveBrowser, DialogButton.OK));
                    DialogMonitor.Dialogs[1].HandlerDelegate = CatchMessage;
                    var saveButton = Manager.ActiveBrowser.Find.ById<HtmlAnchor>("Save");

                    saveButton.Focus();
                    saveButton.MouseClick(MouseClickType.LeftClick);
                    UnexpectedDialogAction action = UnexpectedDialogAction.DoNotHandle;

                     }

                
       void CatchMessage(IDialog dialog)
            {

                try
                {
                    alertmessage = dialog.Window.AllChildren[2].Caption;
                    HandleClass.HandleDialog(dialog.Window.Handle);

                    dialog.Window.Close();
                    throw new ApplicationException(string.Format("The test script cannot be executed because of the error {0}", alertmessage));
                }
                catch (Exception exception)
                {
                    throw exception;

                }
            }

    the line in bold indicates where i am throwing the error and expecting the test to fail.
    Adding to the above, i even tried to access variable /method and assign it the alertmessage value,however it does not work
    Also it is observed that the handler call is not consistant, it sometimes works but sometimes never hits the handler even tough dialog count is 2

    Any help appriciated
    Thanks
  26. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Nov 2011 Link to this post

    Hi Saket,

    A throw within the sub-thread will be ignored by the main testing thread. You will need to move that code to the main thread for it to work.

    Why are you trying to unconditionally throw an exception and fail the test? Please provide more information on your scenario so we can better troubleshoot it.

    Best wishes,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  27. Yani
    Yani avatar
    1 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2012 Link to this post

    I cannot add TelerikCustomHandler.dll to the References. Is there other ways to add it? i've tried several times but it just didn't get in the Project References box.
  28. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 31 Aug 2012 Link to this post

    Hi Yani,

    That DLL is built using .NET 3.5. Test Studio has since been upgraded to use .NET 4.0 and requires assembly references using .NET 4.0. I have recompiled that DLL to use .NET 4.0 and attached it to this post.

    Regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  29. Yeyen
    Yeyen avatar
    3 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    Hello,

    I tried using the attached file but unfortunately I wasn't able to add it in the Project References. Please help. Thanks.
  30. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 19 Sep 2012 Link to this post

    Hello Yeyen,

    Which version of Test Studio do you have installed? Did you try both the TelerikCustomHandlerNET4.zip (which is for .NET 4) and telerikcustomhandler.rar (which is for .NET 3.5)?

    Regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top