Opening the Silverlight web page

7 posts, 0 answers
  1. Amardeep
    Amardeep avatar
    7 posts
    Member since:
    Feb 2013

    Posted 31 Jul 2013 Link to this post

    HI, 

    I am new to TTF, and I am learning to build the framework within our company. I am trying to open the silverlight web page but getting errors.
    I am using the method under to open the webpage:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using ArtOfTest.WebAii.TestTemplates;
    using ArtOfTest.WebAii.Silverlight;
    using ArtOfTest.WebAii.Silverlight.UI;
    using System.Diagnostics;
    using System.IO;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.TestAttributes;
    using ArtOfTest.WebAii.Win32.Dialogs;
    using ArtOfTest.WebAii.Controls.HtmlControls;



    namespace WebPortalTests
    {
        [TestClass]
        public class CreateCharts :BaseTest
        {
            public SilverlightApp OpenApplication()
            {
                Manager.Settings.Web.EnableSilverlight=true;
                Manager.LaunchNewBrowser();
                ActiveBrowser.Window.Maximize();
                ActiveBrowser.NavigateTo("http://Some web page");
                SilverlightApp app = ActiveBrowser.SilverlightApps();
                return app;
            }

        }
    }

    Can you please tell me if I am using the right API method to open the webpage? IF yes what is going wrong in the method?

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 01 Aug 2013 Link to this post

    Hi Amardeep,

    Here is how your code should look like:

    [TestClass]
       public class TelerikVSUnitTest1 : BaseTest
       {
               [TestMethod]
           public void SampleWebAiiTest()
           {
               Manager.Settings.Web.EnableSilverlight = true;
               Manager.LaunchNewBrowser();
               ActiveBrowser.Window.Maximize();
               ActiveBrowser.NavigateTo("http://demos.telerik.com/silverlight/");
               SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
               
           }
     
       }
     
    Firstly you should have [TestMethod] to indicate which part of the code is a test method. Another thing is that the method must have a return type. This sample is returning void, so you don't need to have this line of code: return app;

    The last thing is that ActiveBrowser.SilverlightApps() returns an array of all SL applications on the page, so you have to use index also: SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

    Hope this helps.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Amardeep
    Amardeep avatar
    7 posts
    Member since:
    Feb 2013

    Posted 01 Aug 2013 Link to this post

    HI Boyan, 
    Thanks for your reply.
    I have changed the code but getting the NullReferenceException. Do I need to initialize the Manager class?
    Please see the attached file for the exception

    namespace WebPortalTests
    {
        [TestClass]
        public class CreateCharts :BaseTest
        {
            [TestMethod]
            public void OpenApplication()
            {  
                
                Manager.Settings.Web.EnableSilverlight = true;
                Manager.LaunchNewBrowser();
                ActiveBrowser.Window.Maximize();
                ActiveBrowser.NavigateTo("http://ab-m4500/AthenePortal/Presentation.WRClient.html");
                SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
     
            }
     
        }
    }
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 05 Aug 2013 Link to this post

    Hello Amardeep,

    Yes you might need to initialize it. Here is an example code:

    Settings mySettings = new Settings();
    mySettings.Web.DefaultBrowser = BrowserType.InternetExplorer;
    mySettings.Web.EnableSilverlight = true;
    Manager myManager = new Manager(mySettings);
    myManager.Start();
    myManager.LaunchNewBrowser();
    myManager.ActiveBrowser.NavigateTo("URL", false);
     
    Before that please try to modify you code with manager.current:

    namespace WebPortalTests
     
    {
     
        [TestClass]
     
        public class CreateCharts :BaseTest
     
        {
     
            [TestMethod]
     
            public void OpenApplication()
     
            {   
     
                  
     
                Manager.Current.Settings.Web.EnableSilverlight = true;
     
                Manager.Current.LaunchNewBrowser();
     
                ActiveBrowser.Window.Maximize();
     
                ActiveBrowser.NavigateTo("http://ab-m4500/AthenePortal/Presentation.WRClient.html");
     
                SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
     
       
     
            }
     
       
     
        }
     
    }

    Let me know if you need further assistance.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Alex
    Alex avatar
    1 posts
    Member since:
    Jul 2014

    Posted 09 Sep 2014 Link to this post

    Good day 
    I also learn TTF and encountered this error message:
    "An exception of type 'System.ArgumentException' occurred in ArtOfTest.WebAii.dll but was not handled in user code
    Additional information: Index '0' is invalid. List contains only '0' apps".

    My code:
            public void First()
            {
                // Enable Silverlight
                Settings.Current.Web.EnableSilverlight = true;
                
                // Launch a browser instance
                Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
                
                // Navigate to the page
                ActiveBrowser.NavigateTo("some url");
                
                //Login
                Find.ByAttributes<HtmlDiv>("data-thumbprint=~900ACBBBBFCFE71EEA6C5F3A1A6CDE97EF5E0C3B").Click();
                System.Threading.Thread.Sleep(20000);
                
                // Get an instance of our Silverlight app.
                SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

    Tell me, please, what's the problem?
  6. Vitaliy
    Vitaliy avatar
    20 posts
    Member since:
    Jul 2012

    Posted 10 Sep 2014 Link to this post

    If the use of Manager.LaunchNewBrowser(BrowserType.AspNetHost) tests will be executed or not? or use the BrowserType.SilverlightOutOfBrowser ?
  7. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 12 Sep 2014 Link to this post

    Hello Amardeep,

    Please confirm you are using valid Silverlight application. The best approach here will be providing access to the tested application with the test you are trying to execute so we can assist further.

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