simulate user interaction, custom step and caching

10 posts, 0 answers
  1. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 30 Nov 2010 Link to this post

    hello


    i am currently evaluating your product and so far i am very pleased with my results.
    As i learned from some forum posts it is not possible to run multiple instances on one machine at the same time.
    Because i need to verify correct user interaction and calculation i need to perform some custom actions at specific times, then continue with usual recorder/user actions  and validate the results.

    i was able to reference my assemblies and create some code to write data to the DB but i also need to interact with the cache of the webserver.

    i came up with the following ideas to cover my needs (as i didn't find anything about it in the forums)
    1. use a dummy button to start actions to the webserver and call methods that perform the needed actions. this solution has the drawback of a postback which could change behavior of the application.
    2. create a javascript function that starts an ajax request to the server and passes arguments from the Testing methods to webserver. i can then decide which actions to perform based on the arguement - for example clearing the cache, writing to DB and so on.
    3. calling a web service

    i would prefer solution 2 or something similar.
    if i need to perform an action at a specific testing step i would use something like
    Actions.InvokeScript(@"InitiateTestingStep("" + userid + "","" + TestHelperMethods.ClearCache + "");");
    to pass the userid and an enumeration value.
    the InitiateTestingStep method performs a server callback.
    the function on the server checks for the second paramater to decide which action to perform.

    is this a suitable approach to solve my problem or is there a built-in mechanism?

    regards

  2. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 01 Dec 2010 Link to this post

    Hi karl,

    First, thank you for taking the time to evaluate our products. You posed your question in the WebAii Testing Framework forum, but it sounds like what you're really doing is evaluating our WebUI Test Studio product, either the Dev or QA edition. Is that correct?

    Now to your question/problem, you need to control/clear the web servers cache as part of your testing scenario, do I understand that correctly? I admit there is no built-in feature to accomplish that. You have identified a number of possible solutions. I agree your #2 of your three sounds like the easiest approach.

    The only alternative I can think of would be to write code that would remotely perform an IIS Reset (I'm just assuming you're using IIS) from your testing machine. That would flush all cache's and buffers that IIS maintains. I don't know how to write that code myself, but I imagine it shouldn't be too difficult.

    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
  3. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 01 Dec 2010 Link to this post

    hello


    you are right, i am currently evaluation the dev-edition.
    i wasn't sure where to post this question because it's not related to Dev or QA in particular so i posted it here.

    the iis reset won't work in my scenario as i only need to remove one specific cache item or update the cache.

    i continued to work on solution #2 and had some partial success. so far i can call an ajax method which does my desired actions by using a javascript call on a button click. the button does no postback, only javascript call.
    the javascript function then calls the ajax function on the server which works well.
    i now tried to call the javascript function directly in a test step but this fails.
    i am using the following command:

    Actions.InvokeScript(@"InitiateManualTestStep('" + bidid + "','" + userid + "')");
    where bidid and userid are string variables containing GUIDs and InitiateManualTestStep is the javascript function which then calls the server function. i checked the errorlog and assume, that the test environment can't find the function.
    As mentioned above clicking the button on the page does call the js correclty. Is there anything special i have to do in order to call my own js-functions with the invokeScript method?

    here is the error log output:
    Exception thrown executing coded step: '[clearCache] : @"Clear Cache Javascript Call'.
    InnerException:
    ArtOfTest.WebAii.Exceptions.ExecuteCommandException: ExecuteCommand failed!
    InError set by the client. Client Error:
    System.InvalidOperationException: Javascript call [InitiateManualTestStep(\'78A5D045-D0FA-4557-A19B-4E42C4AF8274\',\'014C2CBB-2CC9-49C9-9F6C-EA2A09389D9F\');] failed! Please make the function exists and the call is using the correct prototype signature. Javascript error: [object Error]
       at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)
       at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)
       at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document)
    BrowserCommand (Type:'Action',Info:'NotSet',Action:'InvokeJsFunction',Target:'ElementId (tagName: '',occurrenceIndex: '-1')',Data:'InitiateManualTestStep(\'78A5D045-D0FA-4557-A19B-4E42C4AF8274\',\'014C2CBB-2CC9-49C9-9F6C-EA2A09389D9F\');',ClientId:'Client_285d814c-e6ba-45db-b1d9-4e924a9e3bf9',HasFrames:'False',FramesInfo:'',TargetFrameIndex:'-1',InError:'True',Response:'System.InvalidOperationException: Javascript call [InitiateManualTestStep(\'78A5D045-D0FA-4557-A19B-4E42C4AF8274\',\'014C2CBB-2CC9-49C9-9F6C-EA2A09389D9F\');] failed! Please make the function exists and the call is using the correct prototype signature. Javascript error: [object Error]
       at ArtOfTest.InternetExplorer.IECommandProcessor.InvokeFunction(String functionCall, Boolean useEval, Boolean returnJSON)
       at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessActionCommands(BrowserCommand request)
       at ArtOfTest.InternetExplorer.IECommandProcessor.ProcessCommand(WebBrowserClass ieInstance, BrowserCommand request, IHTMLDocument2 document)')
    InnerException: none.

    regards
  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 01 Dec 2010 Link to this post

    Hi karl,

    Have you tried folliowing our documentation on how to use the InvokeScript? One subtle formatting quirk you have to follow is you have to double up on any quotes that need to be sent into the script call. For example:

    Actions.InvokeScript(@"Test2(""WebAii"", 4)");

    This will be translated into:

    Test2("WebAii", 4)

    If you have followed that, would you show me the JavaScript function you're trying to call? I'll experiment with it to try and determine what the problem is.

    Sincerely yours,
    Cody
    the Telerik team
    Interested in Agile Testing?

    Tune in Wednesday, December 1st for a very special Webinar focused on Agile Testing. Click here to register for free!
  5. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 02 Dec 2010 Link to this post

    hello

    i checked this documentation and also tried various combinations of single quotes, double quotes no quotes at all...
    i now tried it again with hardcoded IDs and doulbe quotes as in the documentation:

    Actions.InvokeScript(@"InitiateManualTestStep(""78A5D045-D0FA-4557-A19B-4E42C4AF8274"",""014C2CBB-2CC9-49C9-9F6C-EA2A09389D9F"")");

    but without success.
    here is my javascript code ( i added the alerts for testing and then removed them)
    function InitiateManualTestStep(bidID, userID)
    {
        try
        {
          //  alert('working...auction2');
     
            ApplicationBasePageClass.InitiateManualTestStep(bidID, userID, ContentPages_Auction_ViewAuction_ApplyForAuction_ApplyForAuction2_processTestResult);
        }
        catch (e)
        {
            objErrorHandler.HandleError(e.message, "InitiateManualTestStep", "error");
        }
    }
    function ContentPages_Auction_ViewAuction_ApplyForAuction_ApplyForAuction2_processTestResult(valid)
    {
     //   alert('done!');
    }

    this two functions are in one javascript file added to the page.
    the first function calls an Ajax method on the server, the second function gets executed as the answer arrives at the client.

    the server code looks as follows:
    1. register ajax function in Page_Load
    protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender,e);
            try
            {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(ApplicationBasePageClass), this.Page);
            }
             catch (Exception err)
            {
                HandleError(err);
            }
        }
    2. definition of the ajax function called by client
    [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
       public object InitiateManualTestStep(string bidid, string userID)
       {
           ApplicationCacheManager.ClearTenderAuctionCache(bidid, PageHelper); // removes one object from the cache
           return new
           {
               returnValue = true
           };
       }

    Some additional information that might help you identify the problem:
    1. i am using a masterpage in my webapplication
    2. i am using frames but all interaction of my testcase is located in the main frame
    3. the above server code is in the pagebase class. every page inherits from this class so these functionality is available on every page (the javascript is currently added in one page where i try to call the method)

    Is it possible to call the server function directly in the coded step of the test? for example:
    Actions.InvokeScript(@"ApplicationBasePageClass.InitiateManualTestStep(""bidID"", ""userID"", ""ContentPages_Auction_ViewAuction_ApplyForAuction_ApplyForAuction2_processTestResult"")";

    thanks for your fast reply

    regards
  6. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2010 Link to this post

    i watched the webinar about best practices and came up with another question regarding simulate parallel users interacting.

    in a coded step i can open a new window, navigate to url, do whatever i want and then close the window again.
    is it possible to open a new window and then start another test in this window, wait until this test is finished, close the window and then continue with my other test? this way i could wait with User A while User B performs some actions and then continue with User A.

  7. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 03 Dec 2010 Link to this post

    i was able to execute another test in a new browser while pausing the other user.
    i launch a new browser, then used the code produced by executing a subtest and then close the browser:

    Manager.LaunchNewBrowser();
    this.ExecuteTest("Login2.aii");
    Manager.ActiveBrowser.Close();

    this works really fine and this way i should be able to cover most of my needs (so the workaround won't be used that often).
    the only problem i encountered so far is that i have to add and enable both tests in a testlist (if i need CreateLogFile=true) in order the subtest can be found but then the subtest is called also "on its own" because it is in the test list.
    if i integrate the tests in TFS build do i also need to add the subtests to the testlist or are all subtests available for execution by default?
  8. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 03 Dec 2010 Link to this post

    Hello Carl,
     
      If I may interject I would like to propose a different approach.
    You can use an HttpHandlers application. An HttpHandlers executes logic on the server upon accepting an HTTP request. What's really nice about this is that you can make an HTTP request through a browser.
    For instance if your HttpHandlers is called MyHandler then pasting
     http://MyServer:8080/MyHandler?parameter1=value&parameter2=someOtherValue
    to your browser's address bar and hitting enter is a valid HTTP Request to your handler giving it two parameters to work with and return something if necessary.
    The cool thing is that you can just do that in a NavigateTo step from WebUI Test Studio's GUI without writing a single line of code. Just record some random Navigation Step, double click it to expand it and change the URL to your request. Sure beats writing JavaScript functions and then trying to invoke them from a Coded Step.

    An HttpHandlers on the server can do anything that C# executing locally on that server can do. Of course you'll have to have a deployed HttpHandlers on your server. If you don't know how to write one you can find plenty of good tutorials online like this one: http://support.microsoft.com/kb/308001

    Please consider this alternative. If it this won't work we can still explore InvokeScript
    Hope to hear from you soon!

    Best wishes,
    Stoich
    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
  9. karl
    karl avatar
    9 posts
    Member since:
    Nov 2010

    Posted 08 Dec 2010 Link to this post

    hello

    thank you for that additional approach but i am not sure if this can cover my needs.
    as i understood so far from the link you posted this would be deployed in a different web which can then be called by simply entering the address in a browser.
    if so i wouldn't be able to access the cache of the application that is tested. in some rare scenarios i have to update the cache or remove one specific item.


    Do you have any hints why my javascript function isn't working with the InvokeScript function?


    regards
  10. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 08 Dec 2010 Link to this post

    Hi Karl,
       I'm confident this will cover your needs.
     The HttpHandler application won't be deployed in the different location. It will be deployed on the server who's cache you want to clear.

    You can configure your HttpHandler application to work like this:
    is pretty much a single class that holds some logic. The second an Http Get Request is sent to the HttpHandler - this logic gets executed.

    So you make an HttpHandler containing logic that tells it to empty the cache:
    This.EmptyCacheRightNow()

    You build this HttpHandler and you deploy it to the Server that you want relieved of its cache.
    From there there you just need to make a valid Http Get Request. Using a browser to navigate to:
    http://thisIsYourPCsName/ThisIsYourHttpHandlersName
    is a valid Http Get Request without any parameters. You can make this request (i.e. you can have a NavigateTo step to this URL) as many times in your test as you like. You can do it 10 times in a row if like.

    Really, AJAX does the same thing - just not through an HTTP Get Request.

    Please consider giving it a try - once you get the HttpHandler working - all your troubles are over - you can empty the cache from any test as many times as you like. And there are so many tutorials on how to make an HttpHandler online.
     

    Best wishes,
    Stoich
    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top