tags:

views:

5

answers:

0

Hi, I am trying to create a framework which calls many test to run.So thought of implementing Suite attribute provided by Nunit framework.This is my code. Main.cs: using System; using System.Diagnostics; using System.Text; using NUnit.Framework; using Selenium; using System.IO; using NUnit.Core;

namespace SeleniumTests { [TestFixture] public class Main { public static String Current_Path = Directory.GetCurrentDirectory(); public static String Sel_Path_Dir, Actual_Sel_Path; private Process seleniumServer; private ProcessStartInfo seleniumServerProcessStartInfo;

    [TestFixtureSetUp]
    public void TestFixtureSetup()
    {
        Console.WriteLine("1.................");
        //-------------- To find selenium-server.jar absolute path ----------------------------------------------
        char[] splitter = { '\\' };
        Console.WriteLine(Current_Path);
        string[] path_temp = Current_Path.Split(splitter);
        for (int x = 0; x < ((path_temp.Length) - 2); x++)
        {
            if (x == 0)
                Sel_Path_Dir = path_temp[x];
            else
                Sel_Path_Dir = Sel_Path_Dir + '\\' + path_temp[x];
        }
        Actual_Sel_Path = Sel_Path_Dir + "\\lib\\selenium-server-standalone-2.0a5.jar";
        Console.WriteLine(Actual_Sel_Path);
        //-------------------------------------------------------------------------------------------------------
        seleniumServerProcessStartInfo = new ProcessStartInfo("java", "-jar " + "\"" + Actual_Sel_Path + "\"");
        Console.WriteLine("Starting Selenium Server");
        seleniumServer = Process.Start(seleniumServerProcessStartInfo);
    }

    [TestFixtureTearDown]
    public void TestFixtureTearDown()
    {
        Console.WriteLine("2.................");
        Console.WriteLine("Shuting down Selenium Server");
        seleniumServer.CloseMainWindow();
    }

    [Test]
    public void Testcase()
    {
        GoogleTest tc = new GoogleTest();
        tc.Login_App();
    }
}

[TestFixture]
public class AllTests
{
    [Suite]
    public static TestSuite Suite
    {
        get
        {
            Console.WriteLine("Suite.......");
            TestSuite suite = new TestSuite("All Tests");
            suite.Add(new GoogleTest());
            return suite;
        }
    }
}

}

And SeleniumGoogleTest.cs: using System; using System.Diagnostics; using System.Text; using NUnit.Framework; using Selenium;

namespace SeleniumTests { [TestFixture] public class GoogleTest { public ISelenium selenium; private StringBuilder verificationErrors; /*############################################################################################################# # Method : Login_App() # Parameter: Selenium (object) # Return : Null # Description: Performs login operation for the application Clinical Advantage ##############################################################################################################*/ [Test] public void Login_App() { selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com"); selenium.Start(); verificationErrors = new StringBuilder();

        selenium.SetTimeout("3000");
        selenium.Open("/");
        selenium.WindowMaximize();
        selenium.Type("q", "chidambaram");
        selenium.Click("//span[@id='body']/center/form/table/tbody/tr/td[2]/span/span/input");
        selenium.Close();
        selenium.Stop();
    }
}

}

After run, the test is getting execute but not through Suite attribute and finally my test gets fail. Below is my Nunit console output. -----------------------------------------------------------------------------Run.Test:

[loadtasks] Scanning assembly "NAnt.Contrib.Tasks" for extensions. [nunit2] 1................. [nunit2] D:\MyWork\Automation Testing\SeleniumFramework\Automate Test Suite\Sample2\bin\debug [nunit2] Path\lib\selenium-server-standalone-2.0a5.jar [nunit2] Starting Selenium Server [nunit2] 2................. [nunit2] Shuting down Selenium Server [nunit2]

BUILD FAILED

Path\Sample2\nant.build(30,4): Tests Failed.

Total time: 12.3 seconds.

Please guide me on how to use Suite attribute and please provide me some sample on this.

Thanks in advance.

Chidambaram