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

Getting text from a Javascript alert popup

34 Answers 403 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sam Davis
Top achievements
Rank 1
Sam Davis asked on 25 May 2010, 03:20 PM
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.

34 Answers, 1 is accepted

Sort by
0
Missing User
answered on 25 May 2010, 05:21 PM
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.
0
Sam Davis
Top achievements
Rank 1
answered on 26 May 2010, 02:10 PM
Yes I would like to continue working in code to get this to work. I am using the QA Edition.
0
Missing User
answered on 26 May 2010, 07:16 PM
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.
0
Sam Davis
Top achievements
Rank 1
answered on 27 May 2010, 05:06 PM
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.

 

0
Missing User
answered on 27 May 2010, 10:57 PM
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.
0
Sam Davis
Top achievements
Rank 1
answered on 01 Jun 2010, 06:35 PM

Thanks, I got it to work now.

0
Sam Davis
Top achievements
Rank 1
answered on 05 Aug 2010, 03:22 PM
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. 
0
Cody
Telerik team
answered on 05 Aug 2010, 03:28 PM
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
0
Michael Flynn
Top achievements
Rank 1
answered on 29 Sep 2010, 08:51 PM
My script options is not enabled.  How do you enable the script options in the user settings?

thanks.
0
Cody
Telerik team
answered on 29 Sep 2010, 11:47 PM
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
0
Michael Flynn
Top achievements
Rank 1
answered on 30 Sep 2010, 12:17 PM
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
0
Konstantin Petkov
Telerik team
answered on 30 Sep 2010, 12:25 PM
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
0
Michael Flynn
Top achievements
Rank 1
answered on 30 Sep 2010, 12:37 PM
So after I do that, all of the other steps are the same then, right?

Thanks for your help,
Mike
0
Konstantin Petkov
Telerik team
answered on 30 Sep 2010, 01:28 PM
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
0
Sam Davis
Top achievements
Rank 1
answered on 01 Oct 2010, 02:37 PM
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.

 

0
Cody
Telerik team
answered on 04 Oct 2010, 06:22 PM
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
0
Michael Flynn
Top achievements
Rank 1
answered on 04 Oct 2010, 07:04 PM
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()
--------------------------------------------------
0
Michael Flynn
Top achievements
Rank 1
answered on 04 Oct 2010, 08:46 PM
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
0
Mark
Top achievements
Rank 1
answered on 15 Jul 2011, 07:21 AM
Hi Telerik Team,

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

Thanks
0
Mark
Top achievements
Rank 1
answered on 15 Jul 2011, 07:22 AM
Hi Telerik Team,

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

Thanks
0
Mark
Top achievements
Rank 1
answered on 15 Jul 2011, 07:52 AM
Hi Telerik Team,

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

Thanks
0
Mark
Top achievements
Rank 1
answered on 15 Jul 2011, 09:20 AM
Hi Telerik Team,

Is this feature now included in the latest version?
0
Anthony
Telerik team
answered on 15 Jul 2011, 05:30 PM
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?
0
Saket
Top achievements
Rank 1
answered on 23 Nov 2011, 01:35 PM
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
0
Anthony
Telerik team
answered on 28 Nov 2011, 06:32 PM
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
0
Yani
Top achievements
Rank 1
answered on 31 Aug 2012, 03:25 AM
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.
0
Cody
Telerik team
answered on 31 Aug 2012, 04:16 PM
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
0
Yeyen
Top achievements
Rank 1
answered on 19 Sep 2012, 08:49 AM
Hello,

I tried using the attached file but unfortunately I wasn't able to add it in the Project References. Please help. Thanks.
0
Cody
Telerik team
answered on 19 Sep 2012, 07:28 PM
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
0
Yeyen
Top achievements
Rank 1
answered on 20 Sep 2012, 01:49 AM
Hello,

I'm using a Trial Version 2012.1.719.0. And yes i cannot add both the 3.5 and 4.0 versions
0
Cody
Telerik team
answered on 20 Sep 2012, 02:45 PM
Hi Yeyen,

With Trial Version 2012.1.719.0 you should be using TelerikCustomHandlerNET4.zip. Could you please share with me what happens when you try? Here's a video showing it working just fine on my machine using the same Telerik build as you. I used Jing to record this video. it's a good free screen recorder.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Cody
Telerik team
answered on 20 Sep 2012, 05:24 PM
Hi,

I am sorry I forgot to include the link to my video: http://www.screencast.com/t/dfgcvNReg 

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Yeyen
Top achievements
Rank 1
answered on 21 Sep 2012, 01:32 AM
Alright here's the link to the video: http://www.screencast.com/t/VkSMdW36qFQs
0
Cody
Telerik team
answered on 25 Sep 2012, 05:51 PM
Hi Yeyen,

I suspect I know what the problem is. You may be missing the .NET 4 reference assemblies (see first attached screen shot) that this DLL relies on. To fix this you must download and install the Windows 7 SDK. Note you only need to select the Reference Assemblies as shown in the second attached screen shot.

Please let me know whether or not this solves the problem.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Sam Davis
Top achievements
Rank 1
Answers by
Missing User
Sam Davis
Top achievements
Rank 1
Cody
Telerik team
Michael Flynn
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Mark
Top achievements
Rank 1
Anthony
Telerik team
Saket
Top achievements
Rank 1
Yani
Top achievements
Rank 1
Yeyen
Top achievements
Rank 1
Share this question
or