Scripting

8 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 02 Nov 2012 Link to this post

    Hey there,
      I need to test an SPA build with Kendo MVVM.  So pretty much I need to call some set methods on the viewmodel in the test (in javascript), then record\test the results in the viewmodel.  So like test step 1 says $viewModel.set("isActive", true); ...then I check visibility of some items.  Then set it to false, and check other things (etc etc)

    How can I accomplish this?

    Thanks,
    Steve
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 07 Nov 2012 Link to this post

    Hello Steve,

    To make JavaScript calls requires a coded step. For example:

    Actions.InvokeScript("$viewModel.set("isActive", true);");

    You should be able to test the visibility of an element using our standard Element menu that comes with our recorder.

    If you need further assistance let us know, along with any additional details that will help us fully understand your exact test case.

    Regards,
    Cody
    the Telerik team
    Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
    Vote now
  3. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 17 Dec 2012 Link to this post

    Are there plans for a better method?

    I have to do a bunch of pre-work on the page to setup the test and having to script it out as strings (frankly) sucks
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 18 Dec 2012 Link to this post

    Hi Steve,

    Are there plans for a better method?

    Better method to do what? Run JavaScript? Test visibility?

    For running JavaScript, as we see it, you pretty much have to be a programmer in order to know how to put together the correct JavaScript. With this in mind it's not a priority to us to provide a non-coded solution to do this. Adding a coded step, which takes just one line of code, should be an easy thing to do for someone familiar with programming in JavaScript.

    For testing visibility, this is already available on our element menu. I don't see how we can make it any eaiser.

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Dec 2012 Link to this post

    Better method to handle large javascript...

    Sure, if I want to kick off one line, throw in a C# coded step, why not....what if I want to add in a 20+ line jQuery setup or teardown script...that'd be horrible to look at and maintain as one long string.
  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 18 Dec 2012 Link to this post

    Hello,

    I would declare a static variable to hold the JavaScript and reference the variable in the method call:

    private readonly static string initScript = "Codeline 1;" +
        "Codeline 2;" +
        "Codeline 3;";
     
    [CodedStep(@"New Coded Step")]
    public void ScratchTest_CodedStep()
    {
        Actions.InvokeScript(initScript);
    }

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 19 Dec 2012 Link to this post

    Yeah...that's the part that "sucks" :)

    Writing javascript as a string literal in C# is horrible; I've got a huge SPA to test.

    Can we not have a feature request to perhaps load in an run an external script (or does that exist?)....OR an actual javascript window to run the code in there as a step (with syntax highlighting).
  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 19 Dec 2012 Link to this post

    Hi Steve,

    I have created a new feature request for your idea here. In the meantime I would use Visual Studio to create a new .js file in my solution and then write code to load this .js file as a text file into a string variable and pass it into the InvokeScript function.

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