static void LaunchViaCommandLineArguments(string[] args) { var exePath = string.Format("{0}\\SeleniumHubNodeLauncherUI.exe", AppDomain.CurrentDomain.BaseDirectory); Helpers.EncryptConfig(exePath); _AcknowledgeAndCheckArguments(); FileDirOperations.CreateRequiredDirectories(Progress, Options.LogsLocation); try { Helpers.DecryptConfig(exePath); var username = ConfigurationManager.AppSettings["Username"]; var password = ConfigurationManager.AppSettings["Password"]; var domain = ConfigurationManager.AppSettings["Domain"]; _networkCredential = new NetworkCredential(username, password, domain); Helpers.CopySeleniumJars(Progress, true, NetworkPath, _networkCredential); } catch (Win32Exception exception) { Progress.Report(string.Format("An error has occurred while trying to copy files. {0}{1}", exception.Message, Environment.NewLine)); Progress.Report(string.Concat("Attempting to start the hub and node with local versions of the files, if they exist.", Environment.NewLine)); } if (_startHub) { Helpers.StartHub(Options, Progress, out _hubPort); } if (_startNode) { if (_hubPort != default(int)) { Helpers.StartNode(Options, Progress, _hubPort); } else { Progress.Report("Could not start node as the hub wasn't started."); } } }
private void btnGo_Click(object sender, EventArgs e) { txtOutput.Clear(); //Check the system if any selenium processes are running //and sync the data file appropriately. Helpers.CheckAndSyncData(); if (txtHubParams.TextLength != 0) { _options.HubParams = txtHubParams.Text; } if (chkStartNode.Checked && chkCustomNode.Checked) { if (_selectedBrowsers.Any()) { _options.BrowsersList = _selectedBrowsers.ToArray(); } else { MessageBox.Show("Please select at least one browser.", "Custom node options"); return; } _options.Hub = txtHub.Text.Trim(); _options.MaxSessions = string.IsNullOrEmpty(cboMaxSessions.SelectedItem.ToString()) ? _options.MaxSessions : cboMaxSessions.SelectedItem.ToString(); } else { SetDefaultNodeOptions(); } FileDirOperations.CreateRequiredDirectories(_progress, _options.LogsLocation); var filesExistLocally = Helpers.SeleniumJarsExistLocally(); try { Helpers.DecryptConfig(Application.ExecutablePath); var configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); string username = "", password = "", domain = ""; if (txtAltPath.Text != string.Empty) { configuration.AppSettings.Settings["SeleniumExecutablesPath"].Value = txtAltPath.Text; } if (txtAltUsername.Text != string.Empty) { username = txtAltUsername.Text; configuration.AppSettings.Settings["Username"].Value = txtAltUsername.Text; } if (txtAltPassword.Text != string.Empty) { password = txtAltPassword.Text; configuration.AppSettings.Settings["Password"].Value = txtAltPassword.Text; } if (txtAltDomain.Text != string.Empty) { domain = txtAltDomain.Text; configuration.AppSettings.Settings["Domain"].Value = txtAltDomain.Text; } configuration.Save(); Helpers.EncryptConfig(Application.ExecutablePath); _networkPath = ConfigurationManager.AppSettings["SeleniumExecutablesPath"]; _networkCredential = new NetworkCredential(username, password, domain); Helpers.CopySeleniumJars(_progress, true, _networkPath, _networkCredential); _filesCopied = true; } catch (Win32Exception exception) { _progress.Report( string.Format( "An error has occurred while trying to copy files. {0}. Executables Path: {1}. Please try again by providing your credentials at the bottom of the app.{2}", exception.Message, _networkPath, Environment.NewLine)); txtAltPath.Clear(); txtAltPath.Text = _networkPath; if (filesExistLocally) { _progress.Report( string.Concat( "Attempting to start the hub and node with previous versions of the files which exist locally.", Environment.NewLine)); } } //start the hub if all conditions suit if ((_filesCopied || filesExistLocally) && chkStartHub.Checked) { _hub = Helpers.StartHub(_options, _progress, out _hubPort); } if ((_filesCopied || filesExistLocally) && chkStartNode.Checked) { //if localhub not started, set appropriate hubport and hub details if (chkStartHub.Checked == false) { try { var hubDetails = _options.Hub.Split(':'); _hubPort = int.Parse(hubDetails[1]); _options.Hub = hubDetails[0]; } catch (Exception exception) { _hubPort = 0; } } //start the node if all conditions suit if (_hubPort != default(int)) { _node = Helpers.StartNode(_options, _progress, _hubPort); } else { btnGo.Enabled = true; btnShutdown.Enabled = false; _progress.Report("Could not start node as the hub wasn't started or incorrect hub details were given.\r\n" + "\r\n Tip: When connecting to a remote hub, the hub should be specified in \"<machine name>:<port>\" format. " + "\r\nFor example, \"bmsplraluru:4444\" or \"localhost:4445\" without the quotes."); } } //change the buttons state to enable/disable the appropriate ones. if (_hub != null || _node != null) { btnGo.Enabled = false; btnShutdown.Enabled = true; } }
public static void Main(string[] args) { var exePath = string.Format("{0}\\SeleniumHubNodeLauncherConsole.exe", AppDomain.CurrentDomain.BaseDirectory); Helpers.EncryptConfig(exePath); if (Parser.Default.ParseArguments(args, Options)) { try { _AcknowledgeAndCheckArguments(); } catch (JsonException e) { System.Console.WriteLine( "There was a problem parsing HubParams. The HubParams are expected to be in a Json string format. Please see the exception and make necessary corrections. {0}", e); Options.GetUsage(); Environment.Exit(1); } //If the options are to stop hub and/or node... if (Options.StopHub || Options.StopNode) { if (Options.StopHub && _hub != null) { _hub.ShutDown(); Progress.Report(string.Concat("Hub shutdown successfully.", Environment.NewLine)); } if (Options.StopNode && _node != null) { _node.ShutDown(); Progress.Report(string.Concat("Node shutdown successfully.", Environment.NewLine)); } Environment.Exit(0); } FileDirOperations.CreateRequiredDirectories(Progress, Options.LogsLocation); var filesExistLocally = Helpers.SeleniumJarsExistLocally(); try { Helpers.DecryptConfig(exePath); var username = ConfigurationManager.AppSettings["Username"]; var password = ConfigurationManager.AppSettings["Password"]; var domain = ConfigurationManager.AppSettings["Domain"]; _networkCredential = new NetworkCredential(username, password, domain); Helpers.CopySeleniumJars(Progress, true, NetworkPath, _networkCredential); _filesCopied = true; } catch (Win32Exception exception) { Progress.Report( string.Format( "An error has occurred while trying to copy files from {1}. {0}.{2}", exception.Message, NetworkPath, Environment.NewLine)); if (filesExistLocally) { Progress.Report( string.Concat( "Attempting to start the hub and node with previous versions of the files which exist locally.", Environment.NewLine)); } } if ((_filesCopied || filesExistLocally) && _startHub) { _hub = Helpers.StartHub(Options, Progress, out _hubPort); } if ((_filesCopied || filesExistLocally) && _startNode) { if (_hubPort != default(int)) { _node = Helpers.StartNode(Options, Progress, _hubPort); } else { Progress.Report("Could not start node as the hub wasn't started."); } } } }