Exemple #1
0
        /// <summary>
        /// Start IIS Express according with optional parameters
        /// overriding the default configuration in App.config
        /// Server: IIS Express, optionally overrides %PROGRAMFILES%\IIS Express\iisexpress.exe
        /// Root: server application root directory
        /// Port: port to listen on
        /// RequestTimeout: expected duration of all tests in sec
        /// ServerStartTimeout: expected start time of the server in sec
        /// </summary>
        /// <param name="server">IIS Express, usually %PROGRAMFILES%\IIS Express\iisexpress.exe</param>
        /// <param name="root">server application root directory</param>
        /// <param name="port">port to listen on</param>
        /// <param name="timeout">expected duration of all tests in sec</param>
        /// <param name="servertimeout">expected start time of the server in sec</param>
        public static void StartServer(this ITestServer inst, string server = null, string root = null,
                                       int?port = null, int?timeout = null, int?servertimeout = null)
        {
            string cserver = server ?? ConfigurationManager.AppSettings["Server"] ??
                             @"%PROGRAMFILES%\IIS Express\iisexpress.exe";
            string croot          = root ?? ConfigurationManager.AppSettings["Root"];
            int    cport          = port ?? int.Parse(ConfigurationManager.AppSettings["Port"]);
            int    ctimeout       = timeout ?? int.Parse(ConfigurationManager.AppSettings["RequestTimeout"]);
            int    cservertimeout = servertimeout ?? int.Parse(ConfigurationManager.AppSettings["ServerStartTimeout"]);

            var info = new ProcessStartInfo();

            info.FileName = cserver.Replace("%PROGRAMFILES%",
                                            System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
            var path = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.WorkDirectory, croot));

            info.Arguments       = String.Format("/path:{0} /port:{1} /trace:error", path, cport);
            info.UseShellExecute = true;
            inst.ServerProcess   = Process.Start(info);
            TestServerExtensionBase.WaitForServerPort(cport, cservertimeout);
            SeleniumExtensionBase.OutOfProcess   = true;
            SeleniumExtensionBase.Port           = cport;
            SeleniumExtensionBase.RequestTimeout = ctimeout;
            inst.driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ctimeout); // too late after OneTimeSetUBrowser()

            TestServerIPC.CreateOrOpenMmmfs();                                         // Create as parent process
        }
Exemple #2
0
        /// <summary>
        /// Start the web application .exe as web server with optional parameters
        /// overriding the default configuration in appsettings.json:
        /// Server: path to the server.exe (the .NET Core binary)
        /// Root: server application root directory
        /// Port: port to listen on
        /// RequestTimeout: expected duration of all tests in sec
        /// ServerStartTimeout: expected start time of the server in sec
        /// </summary>
        /// <param name="config">default configuration</param>
        /// <param name="server">explicit path to the server.exe (the .NET Core binary)</param>
        /// <param name="root">explicit server application root directory</param>
        /// <param name="port">explicit port to listen on</param>
        /// <param name="timeout">explicit expected duration of all tests in sec</param>
        /// <param name="servertimeout">expected start time of the server in sec</param>
        public static void StartServer(this ITestServer inst, IConfiguration config,
                                       string server = null, string root       = null, int?port = null,
                                       int?timeout   = null, int?servertimeout = null)
        {
            string cserver        = server ?? config["Server"];
            string croot          = root ?? config["Root"];
            int    cport          = port ?? config.GetValue <int>("Port");
            int    ctimeout       = timeout ?? config.GetValue <int>("RequestTimeout");
            int    cservertimeout = servertimeout ?? config.GetValue <int>("ServerStartTimeout");

            var info = new ProcessStartInfo();

            info.FileName         = Path.GetFullPath(Path.Join(TestContext.CurrentContext.WorkDirectory, cserver));
            info.Arguments        = String.Format("--urls=http://localhost:{0}/", cport);
            info.WorkingDirectory = Path.GetFullPath(Path.Join(TestContext.CurrentContext.WorkDirectory, croot));
            info.UseShellExecute  = true;
            inst.ServerProcess    = Process.Start(info);
            TestServerExtensionBase.WaitForServerPort(cport, cservertimeout);
            SeleniumExtensionBase.OutOfProcess   = true;
            SeleniumExtensionBase.Port           = cport;
            SeleniumExtensionBase.RequestTimeout = ctimeout;
            inst.driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ctimeout); // too late after OneTimeSetUBrowser()

            TestServerIPC.CreateOrOpenMmmfs();                                         // Create as parent process
        }