Forum Discussion

bgran05's avatar
bgran05
Occasional Contributor
8 years ago

browser as variable or parameter to NUnit scripts?

Hi, 

 

I am wondering is it possible to use a browser loop when you are running Selenium Nunit tests as Test Items?

 

I currently have Test Fixtures that use Test Fixture attributes to define the browser in the Selenium *.cs scripts themselves. For example, this would make my test first run in Chrome, then in Edge:

 

[TestFixture("Chrome")]

[TestFixture("Edge")]

 

Could I control this from outside my Selenium scripts in Test Complete? I am not sure how I would pass the variable of which browser I am running to my scripts, since they are written in C#.

 

Any advice is appreciated! Thanks!

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Let's say you have added the test object "SeleniumTests" to your test project.  In there, you have your assembly and you've specified your TestFixture.  I haven't tried this, but apparently, when you add your test fixture, you do have the option to specific parameters.  So, somewhere in there, there's a parameter call to execute the test fixture.

     

    Give this a try.  Where your object is called "SeleniumTests" and the NUnit test you've added you've called "TestFixture", will this script code work?

    function testAllBrowsers(){
        for (var i = 0; i < Browsers.Count; i++) {
            SeleniumTests.TestFixture.Execute(Browsers.Item(i).Family);
        }
    }

    Or... perhaps if there are parameters that need to be set you would have to do something like

     

    function testAllBrowsers(){
        for (var i = 0; i < Browsers.Count; i++) {
            SeleniumTests.TestFixture.BrowserName = Browsers.Item(i).Family;
            SeleniumTests.TestFixture.Execute();
        }
    }

    Some things worth exploring, I guess... I haven't done much with the Selenium interfacing but something on these lines probably exists SOMEWHERE.

    • bgran05's avatar
      bgran05
      Occasional Contributor

      Thank you so much for your quick response. I am not 100% sure yet where to put that function. I think I need to learn TestComplete itself a bit more. 

       

      I did try making a keyword test like this:

       

      Browser Loop: Chrome, Edge

            Run Code Snippet: Value = UnitTesting.SeleniumTests.Execute(Browsers.CurrentBrowser)

       

      What this does is launches the browser (Chrome is the first), then it tries to run my test. My web drivers in the test not able to pick up that browser from the loop. I will keep taking a look at this.

       

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Selenium driver can use only the browser that it (driver) started. Selenium driver cannot attach to the already running browser. This is one of Selenium's essentials and I am really doubting this ever will be changed.

        So, the only option you have, is to store browser's name in some configuration file written from TestComplete, read the name from this file in your Selenium test and proceed accordingly.