How to execute script step in a recorded test ?

14 posts, 0 answers
  1. Shilpa
    Shilpa avatar
    4 posts
    Member since:
    Jan 2012

    Posted 03 Feb 2012 Link to this post

    I am new to Telerik . I have recorded a sample test given in user guide. I used data binding feature to bind  a local data  table to text input
    in a search box of web page. I want to verify whether it extracted correct value from table and putting it in to text box. When I run test it shows launching browser, going to url but then it just hang up. Is there any way to check the extracted value from data table at run time like getting it displayed in messagebox. I tried using  a script step to insert a script step " MessageBox("Value of Col is")
    in the code behind file. But I received an exception with function name not found?
    Please help me out. Thanks in advance for your time and help!

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 03 Feb 2012 Link to this post

    Hello Shilpa,

    See this code sample article on how to add a MessageBox to a test. Take note of the final pair of code blocks that demonstrate using it with data-driven testing.

    Greetings,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Shilpa
    Shilpa avatar
    4 posts
    Member since:
    Jan 2012

    Posted 03 Feb 2012 Link to this post

    Thanks for your time. I tried that but while executing test I get - System.ArgumentException: The coded step method 'WebTest_CodedStep' does not exist.Please find attached screenshot of the error.
    One another issue I came across is while using test as a test step. I created a test "WebTest". In another test I used "WebTest" as a test step.
    But while executing it doesn't run and log file shows Not run status for this step.
    Thanks

    Do I need to link some other files to the test so that it can understand and execute code behind file?
  4. Shilpa
    Shilpa avatar
    4 posts
    Member since:
    Jan 2012

    Posted 03 Feb 2012 Link to this post

    While researching more I got following error messages:

    C:\Learning\TestProject2\WebTest.tstest.vb: Line 5: (BC40056) Namespace or type specified in the Imports 'System.Windows.Forms' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
    C:\Learning\TestProject2\WebTest.tstest.vb: Line 76: (BC30002) Type 'NativeWindow' is not defined.
    C:\Learning\TestProject2\WebTest.tstest.vb: Line 78: (BC30451) 'MessageBox' is not declared. It may be inaccessible due to its protection level.

    Looks like it can not find NativeWindow constructor in System.Windows.Forms on my machine Windows 7 (Telerik Test Studio 2011.2.1305.0)

    Thanks!
  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 03 Feb 2012 Link to this post

    Hello Shilpa,

    Here is the entire code-behind file of a similar test I created. Compare it to yours and see what's different:

    Imports Telerik.WebAii.Controls.Html
    Imports Telerik.WebAii.Controls.Xaml
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Linq
     
    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 System.Windows.Forms
     
        Public Class WebTest
            Inherits BaseWebAiiTest
     
    #Region "[ Dynamic Pages Reference ]"
     
            Private _pages As Pages
             
            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
     
            <CodedStep("New Coded Step")> _
            Public Sub WebTest_CodedStep()
                Dim window As New NativeWindow()
                window.AssignHandle(ActiveBrowser.Window.Handle)
                MessageBox.Show(window, Data("Col1").ToString())
            End Sub
        End Class

    Ensure you properly Added an Assembly Reference to System.Windows.Forms as mentioned at the top of the previously linked MessageBox article. The only way I replicated those 3 errors together is if I deliberately removed that reference.

    All the best,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Shilpa
    Shilpa avatar
    4 posts
    Member since:
    Jan 2012

    Posted 07 Feb 2012 Link to this post

    Thanks a lot!

    It worked. The problem with me was the location of System.windows.Forms
    I had to include in project >settings> Script Options> Add reference to this dll from my local drive.
    By simply adding it as  imports systems.windows.forms , it was not working.

    Thanks again!
  7. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 23 Aug 2012 Link to this post

    Hi Anthony


    I HAve the Same Problem

    '8/23/2012 11:03:25 AM' - Detected custom code in test. Locating test assembly: com.REGEN.Apps.EnviroGridPortal.IT.dll.
    '8/23/2012 11:03:25 AM' - Assembly Found:
    2012-08-23 11_02_57
    '8/23/2012 11:03:25 AM' - Loading code class:
    ------------------------------------------------------------
    '8/23/2012 11:03:25 AM' - Error attempting to execute a Test As Step. Details:
    '8/23/2012 11:03:25 AM' - System.ArgumentException: Unable to find the test class type ' in your test assembly. Please make sure your test code behind is compiled with your latest changes.
       at ArtOfTest.WebAii.Design.Execution.ExecutionUtils.EnsureTypeExists(Assembly assm, String typeName)
       at ArtOfTest.WebAii.Design.Execution.ExecutionUtils.CreateCodedTestInstance(Test test, TestResult result, String binariesFolder)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteTestInCurrentContext(Test test)

    <<< Test-as-Step 'SWR15_Display_Site.tstest' log ends.


    I have Test as A step, in that test i  have coded step. but with the quick execute its working.  I've verified all the System.imports as you given.




    And Tried Anothe option that, I ve added a new coded step in the Same test instead of calling test as a step

    i'm getting this
    ------------------------------------------------------------
    '8/23/2012 12:57:53 PM' - Starting execution....
    '8/23/2012 12:58:01 PM' - Detected custom code in test. Locating test assembly:
    '8/23/2012 12:58:01 PM' - Assembly Found:
    '8/23/2012 12:58:01 PM' -
    '8/23/2012 12:58:01 PM' - Failure detected during execution. Details:
    ------------------------------------------------------------
    '8/23/2012 12:58:01 PM' - System.ArgumentException: The coded step method 'SWR16_CreateSite_DuplicateSiteID_CodedStep1' does not exist.
       at ArtOfTest.WebAii.Design.Execution.ExecutionContext.SetNewBrowserTracking(Test test, Object codeBehind)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult)
       at ArtOfTest.WebAii.Design.Execution.TestExecuteProxy.ExecuteTest(Test test, Settings settings, String deploymentFolder, String binariesFolder, ExecutionType exeType, Guid firstStepGuid, Guid lastStepGuid, IntPtr existingBrowserHandle, DebuggerOptions debuggerOptions)



    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Linq;
    using System.Diagnostics;
    using Telerik.WebAii.Controls.Html;
    using Telerik.WebAii.Controls.Xaml;


    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 System.Windows.Forms;

    namespace com.REGEN.Apps.EnviroGridPortal.IT
    {

        //
        // 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 SWR16CreateSiteDuplicateSiteID : 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

            [CodedStep(@"@\New Coded Step")]
            public void SWR16_CreateSite_DuplicateSiteID_CodedStep()
            {
                System.Diagnostics.Process pro = new System.Diagnostics.Process();
                pro.StartInfo.FileName = "restore_daq_test.bat";
                pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                pro.Start();
                pro.WaitForExit();
            }

    This is the new step i've  added
            [CodedStep(@"Listed Sites")]
            public void SWR16_CreateSite_DuplicateSiteID_CodedStep1()
            {
                HtmlTable table = Find.ByExpression<HtmlTable>("tagindex=table:0", "tagname=table");
                HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("tagname=tr", "innertext=~Test site");
                Assert.IsNotNull(row, "Site not in a List");

            }
  8. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 28 Aug 2012 Link to this post

    Hello Siva,

    This is usually caused by a mismatch between the code for a coded step and XML for the test file (.tstest or .aii file). Look at the code file and what the name of the class is. For example:

    public class SWR16CreateSiteDuplicateSiteID : BaseWebAiiTest

    The name of the class must match the definition contained in the test file. Now open the test file in a text or XML editor. Look for the <TestClass> line. It should contain something like:
    <TestAssembly>com.REGEN.Apps.EnviroGridPortal.IT.dll</TestAssembly>
    <TestAssemblyPath>bin\Debug\</TestAssemblyPath>
    <TestClass>com.REGEN.Apps.EnviroGridPortal.IT.SWR16CreateSiteDuplicateSiteID</TestClass>

    The assembly name ("com.REGEN.Apps.EnviroGridPortal.IT" in this example) must match the name of the test project. The class name ("SWR16CreateSiteDuplicateSiteID" in this example) must match the class of the test. If either do not match you will get this error message.

    If you continue to have difficulty, please send us the whole project(into a zip file), so we can review it and definitely say what the problem is.

    Kind regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  9. Sangamnath
    Sangamnath avatar
    3 posts
    Member since:
    Mar 2013

    Posted 13 Mar 2013 Link to this post

    Hi Team,
    I am newbie to the Test studio tool and facing the below issue when i try to record and run the script. Please help me to resolve this issue

    Error Log:

    Overall Result: Fail
    ------------------------------------------------------------
    '03/13/2013 12:34:35 PM' - Using .Net Runtime version: '4.0.30319.296' for test execution. Build version is '2012.2.1420.0'.
    '03/13/2013 12:34:35 PM' - Starting execution....
    ------------------------------------------------------------
    ------------------------------------------------------------
    '03/13/2013 12:34:49 PM' - Using 'InternetExplorer' version '9.0' as default browser. 
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:50 PM' - LOG: Unexpected dialog encountered. Taking no action.
    '03/13/2013 12:34:55 PM' - 'Fail' : 1. Wait '5000' msec for url:'http://43.88.67.160/SonyMusicApp/Pages/DashboardAdmin.aspx'
    ------------------------------------------------------------
    Failure Information: 
    ~~~~~~~~~~~~~~~
    Wait for condition has timed out
    InnerException:
    System.TimeoutException: Wait for condition has timed out
       at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
       at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
       at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout)
       at ArtOfTest.WebAii.Core.Browser.WaitForUrl(String url, Boolean isPartial, Int32 timeout)
       at ArtOfTest.WebAii.Design.IntrinsicTranslators.Descriptors.WaitForUrlActionDescriptor.Execute(Browser browser)
       at ArtOfTest.WebAii.Design.Extensibility.HtmlActionDescriptor.Execute(IAutomationHost autoHost)
       at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.ExecuteStep(Int32 order)
    ------------------------------------------------------------
    '03/13/2013 12:34:55 PM' - Detected a failure. Step is marked 'ContinueOnFailure=False' aborting test execution.
    ------------------------------------------------------------
    '03/13/2013 12:34:55 PM' - Overall Result: Fail
    '03/13/2013 12:34:55 PM' - Duration: [0 min: 6 sec: 280 msec]
    ------------------------------------------------------------
    '03/13/2013 12:34:56 PM' - Test completed!

  10. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 13 Mar 2013 Link to this post

    Hello Sangamnath,

    Looking the log it seems that the "Navigate" step is missing and your test starts with "Wait for URL" step instead. You need to have a navigation step at the beginning of the test in order to open the page and execute the rest of the recorded steps. Just enter a URL in the navigation bar in a recording browser as seen in this video and the navigate step will be added to your test.

    If you continue to have difficulty, please provide a copy of your test(in a .zip file) for analysis.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  11. Sangamnath
    Sangamnath avatar
    3 posts
    Member since:
    Mar 2013

    Posted 13 Mar 2013 Link to this post

    Thank team !!!
     The Recorded script is working as expected.

    I wanted to add the timestamp basically wait after every click action.. can you please provide the generic step instead of adding it manually after every line. Thanks 
  12. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 13 Mar 2013 Link to this post

    Hi Sangamnath,

    I am glad to hear you got it working!

    Any action step (eg. Click, Hover, Type) will inherently wait for its respective element for an amount of time based on the 'Wait on elements timeout' setting (see step 7 here for where to increase this value). The identical property also exists for test lists and can be found in the Test List Settings under the General tab (named ElementWaitTimeout).

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  13. Sangamnath
    Sangamnath avatar
    3 posts
    Member since:
    Mar 2013

    Posted 15 Mar 2013 Link to this post

    Hi Team ,
    Thanks for the update !!!

    Also wanted to know whether telerik's test studio support  WAI 'A' Compliance. If Yes please do let us know the accessibilty settings that it support. Thanks 

    Regards,
    Sangamnath
  14. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 20 Mar 2013 Link to this post

    Hi Sangamnath,

    Unfortunately we don't have experience with such applications and I'm not sure what accessibility settings you are refering to. However as far as I know everything that makes your application accessible is implemented in the HTML and all that Test Studio does is to work with the HTML(actions, verifications and etc.), so I believe the answer to your question is yes, you should be able to automate such application with Test Studio. If you are experiencing any difficulties, please provide direct access to your application and detailed description of the issue and we'll do our best to help and provide you with a workable solution. 

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