Exemplo n.º 1
0
        private EnvironmentManager()
        {
            // TODO(andre.nogueira): Error checking to guard against malformed config files
            string driverClassName = GetSettingValue("Driver");
            string assemblyName = GetSettingValue("Assembly");
            Assembly assembly = Assembly.Load(assemblyName);
            driverType = assembly.GetType(driverClassName);
            browser = (Browser)Enum.Parse(typeof(Browser), GetSettingValue("DriverName"));
            remoteCapabilities = GetSettingValue("RemoteCapabilities");

            urlBuilder = new UrlBuilder();

            string currentDirectory = this.CurrentDirectory;
            DirectoryInfo info = new DirectoryInfo(currentDirectory);
            while (info != info.Root && string.Compare(info.Name, "build", StringComparison.OrdinalIgnoreCase) != 0)
            {
                info = info.Parent;
            }

            info = info.Parent;
            webServer = new TestWebServer(info.FullName);
            bool autoStartRemoteServer = false;
            if (browser == Browser.Remote)
            {
                autoStartRemoteServer = bool.Parse(GetSettingValue("AutoStartRemoteServer"));
            }

            remoteServer = new RemoteSeleniumServer(info.FullName, autoStartRemoteServer);
        }
Exemplo n.º 2
0
        private EnvironmentManager()
        {
            // TODO(andre.nogueira): Error checking to guard against malformed config files
            string driverClassName = GetSettingValue("Driver");
            string assemblyName = GetSettingValue("Assembly");
            Assembly assembly = Assembly.Load(assemblyName);
            driverType = assembly.GetType(driverClassName);
            browser = (Browser)Enum.Parse(typeof(Browser), GetSettingValue("DriverName"));
            remoteCapabilities = GetSettingValue("RemoteCapabilities");

            urlBuilder = new UrlBuilder();

            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            string assemblyLocation = executingAssembly.Location;

            // If we're shadow copying,. fiddle with 
            // the codebase instead 
            if (AppDomain.CurrentDomain.ShadowCopyFiles)
            {
                Uri uri = new Uri(executingAssembly.CodeBase);
                assemblyLocation = uri.LocalPath;
            }

            string currentDirectory = Path.GetDirectoryName(assemblyLocation);
            DirectoryInfo info = new DirectoryInfo(currentDirectory);
            while (info != info.Root && string.Compare(info.Name, "build", StringComparison.OrdinalIgnoreCase) != 0)
            {
                info = info.Parent;
            }

            info = info.Parent;
            webServer = new TestWebServer(info.FullName);
            bool autoStartRemoteServer = false;
            if (browser == Browser.Remote)
            {
                autoStartRemoteServer = bool.Parse(GetSettingValue("AutoStartRemoteServer"));
            }

            remoteServer = new RemoteSeleniumServer(info.FullName, autoStartRemoteServer);
        }
Exemplo n.º 3
0
        private EnvironmentManager()
        {
            string currentDirectory  = this.CurrentDirectory;
            string defaultConfigFile = Path.Combine(currentDirectory, "appconfig.json");
            string configFile        = TestContext.Parameters.Get <string>("ConfigFile", defaultConfigFile).Replace('/', Path.DirectorySeparatorChar);

            string          content = File.ReadAllText(configFile);
            TestEnvironment env     = JsonConvert.DeserializeObject <TestEnvironment>(content);

            bool          captureWebServerOutput     = TestContext.Parameters.Get <bool>("CaptureWebServerOutput", env.CaptureWebServerOutput);
            bool          hideWebServerCommandPrompt = TestContext.Parameters.Get <bool>("HideWebServerCommandPrompt", env.HideWebServerCommandPrompt);
            string        activeDriverConfig         = TestContext.Parameters.Get("ActiveDriverConfig", env.ActiveDriverConfig);
            string        activeWebsiteConfig        = TestContext.Parameters.Get("ActiveWebsiteConfig", env.ActiveWebsiteConfig);
            string        driverServiceLocation      = TestContext.Parameters.Get("DriverServiceLocation", env.DriverServiceLocation);
            DriverConfig  driverConfig  = env.DriverConfigs[activeDriverConfig];
            WebsiteConfig websiteConfig = env.WebSiteConfigs[activeWebsiteConfig];

            this.driverFactory = new DriverFactory(driverServiceLocation);
            this.driverFactory.DriverStarting += OnDriverStarting;

            Assembly driverAssembly = Assembly.Load(driverConfig.AssemblyName);

            driverType         = driverAssembly.GetType(driverConfig.DriverTypeName);
            browser            = driverConfig.BrowserValue;
            remoteCapabilities = driverConfig.RemoteCapabilities;

            urlBuilder = new UrlBuilder(websiteConfig);

            // When run using the `bazel test` command, the following environment
            // variable will be set. If not set, we're running from a build system
            // outside Bazel, and need to locate the directory containing the jar.
            string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR");

            if (string.IsNullOrEmpty(projectRoot))
            {
                // Walk up the directory tree until we find ourselves in a directory
                // where the path to the Java web server can be determined.
                bool          continueTraversal = true;
                DirectoryInfo info = new DirectoryInfo(currentDirectory);
                while (continueTraversal)
                {
                    if (info == info.Root)
                    {
                        break;
                    }

                    foreach (var childDir in info.EnumerateDirectories())
                    {
                        // Case 1: The current directory of this assembly is in the
                        // same direct sub-tree as the Java targets (usually meaning
                        // executing tests from the same build system as that which
                        // builds the Java targets).
                        // If we find a child directory named "java", then the web
                        // server should be able to be found under there.
                        if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            continueTraversal = false;
                            break;
                        }

                        // Case 2: The current directory of this assembly is a different
                        // sub-tree as the Java targets (usually meaning executing tests
                        // from a different build system as that which builds the Java
                        // targets).
                        // If we travel to a place in the tree where there is a child
                        // directory named "bazel-bin", the web server should be found
                        // in the "java" subdirectory of that directory.
                        if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            string javaOutDirectory = Path.Combine(childDir.FullName, "java");
                            if (Directory.Exists(javaOutDirectory))
                            {
                                info = childDir;
                                continueTraversal = false;
                                break;
                            }
                        }
                    }

                    if (continueTraversal)
                    {
                        info = info.Parent;
                    }
                }

                projectRoot = info.FullName;
            }
            else
            {
                projectRoot += "/selenium";
            }

            webServer = new TestWebServer(projectRoot, captureWebServerOutput, hideWebServerCommandPrompt);
            bool autoStartRemoteServer = false;

            if (browser == Browser.Remote)
            {
                autoStartRemoteServer = driverConfig.AutoStartRemoteServer;
            }

            remoteServer = new RemoteSeleniumServer(projectRoot, autoStartRemoteServer);
        }