public void Init() { NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection; //.GetSection("capabilities/" + profile) as NameValueCollection; NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection; DesiredCapabilities capability = new DesiredCapabilities(); foreach (string key in caps.AllKeys) { capability.SetCapability(key, caps[key]); } foreach (string key in settings.AllKeys) { capability.SetCapability(key, settings[key]); } String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME"); if (username == null) { username = ConfigurationManager.AppSettings.Get("user"); } String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY"); if (accesskey == null) { accesskey = ConfigurationManager.AppSettings.Get("key"); } capability.SetCapability("os_version", "11.0"); capability.SetCapability("device", "iPhone X"); capability.SetCapability("real_mobile", "true"); capability.SetCapability("browserstack.local", "false"); capability.SetCapability("browserstack.user", "mahendrasinghdho1"); capability.SetCapability("browserstack.key", "eMx8QcXXPftPhgEcVUmd"); String appId = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID"); if (appId != null) { capability.SetCapability("app", appId); } if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true") { browserStackLocal = new Local(); List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accesskey) }; browserStackLocal.start(bsLocalArgs); } string server = ConfigurationManager.AppSettings.Get("server"); driver = new RemoteWebDriver(new Uri("http://" + server + "/wd/hub/"), capability); }
public void Init() { var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection; NameValueCollection environment = ConfigurationManager.GetSection("desktopEnvironments/" + os) as NameValueCollection; NameValueCollection browser = ConfigurationManager.GetSection("desktopBrowsers/" + browserName) as NameValueCollection; DesiredCapabilities capability = new DesiredCapabilities(); foreach (string key in caps.AllKeys) { capability.SetCapability(key, caps[key]); } foreach (string key in environment.AllKeys) { capability.SetCapability(key, environment[key]); } foreach (string key in browser.AllKeys) { capability.SetCapability(key, browser[key]); } String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME"); if (username == null) { username = ConfigurationManager.AppSettings.Get("user"); } String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY"); if (accesskey == null) { accesskey = ConfigurationManager.AppSettings.Get("key"); } capability.SetCapability("browserstack.user", username); capability.SetCapability("browserstack.key", accesskey); if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true") { browserStackLocal = new Local(); List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accesskey) }; browserStackLocal.start(bsLocalArgs); } driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability); }
public void Init() { testParams = PNUnitServices.Get().GetTestParams(); string profile = testParams[0]; string environment = testParams[1]; NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection; NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection; DesiredCapabilities capability = new DesiredCapabilities(); foreach (string key in caps.AllKeys) { capability.SetCapability(key, caps[key]); } foreach (string key in settings.AllKeys) { capability.SetCapability(key, settings[key]); } String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME"); if (username == null) { username = ConfigurationManager.AppSettings.Get("user"); } String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY"); if (accesskey == null) { accesskey = ConfigurationManager.AppSettings.Get("key"); } capability.SetCapability("browserstack.user", username); capability.SetCapability("browserstack.key", accesskey); if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true") { browserStackLocal = new Local(); List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accesskey) }; browserStackLocal.start(bsLocalArgs); } driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability); }
static void Main(string[] args) { Local local = new Local(); List<KeyValuePair<string, string>> options = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("key", BROWSERSTACK_ACCESS_KEY), //new KeyValuePair<string, string>("localIdentifier", "identifier"), //new KeyValuePair<string, string>("f", "C:\\Users\\Admin\\Desktop\\"), new KeyValuePair<string, string>("onlyAutomate", "true"), new KeyValuePair<string, string>("verbose", "true"), new KeyValuePair<string, string>("forcelocal", "true"), new KeyValuePair<string, string>("binarypath", "C:\\Users\\Admin\\Desktop\\BrowserStackLocal.exe"), new KeyValuePair<string, string>("logfile", "C:\\Users\\Admin\\Desktop\\local.log"), }; local.start(options); // Run WebDriver Tests IWebDriver driver; DesiredCapabilities capability = DesiredCapabilities.Firefox(); capability.SetCapability("browserstack.user", BROWSERSTACK_USERNAME); capability.SetCapability("browserstack.key", BROWSERSTACK_ACCESS_KEY); //capability.SetCapability("browserstack.localIdentifier", "identifier"); capability.SetCapability("browserstack.local", true); capability.SetCapability("build", "build"); driver = new RemoteWebDriver( new Uri("http://hub.browserstack.com/wd/hub/"), capability ); driver.Navigate().GoToUrl("http://www.google.com"); Console.WriteLine(driver.Title); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Browserstack"); query.Submit(); Console.WriteLine(driver.Title); driver.Quit(); local.stop(); Console.WriteLine("Test Completed."); Console.ReadLine(); }
public void Init() { NameValueCollection caps = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection; NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection; DesiredCapabilities capability = new DesiredCapabilities(); foreach (string key in caps.AllKeys) { capability.SetCapability(key, caps[key]); } foreach (string key in settings.AllKeys) { capability.SetCapability(key, settings[key]); } String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME"); if (username == null) { username = ConfigurationManager.AppSettings.Get("user"); } String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY"); if (accesskey == null) { accesskey = ConfigurationManager.AppSettings.Get("key"); } capability.SetCapability("browserstack.user", username); capability.SetCapability("browserstack.key", accesskey); Object local_cap = capability.GetCapability("browserstack.local"); Console.WriteLine("Befor checking local"); if (local_cap != null && local_cap.ToString().Equals("true")) { //capability.SetCapability("browserstack.localIdentifier", "DummyTest123"); //capability.SetCapability("binarypath", "/Users/rajnish/Downloads/BrowserStackLocal"); browserStackLocal = new Local(); Console.WriteLine("Inside local"); //Console.WriteLine(browserStackLocal.isRunning().ToString()); List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("key", accesskey), new KeyValuePair <string, string>("binarypath", "path") }; if (!browserStackLocal.isRunning()) { Console.WriteLine(browserStackLocal.isRunning()); browserStackLocal.start(bsLocalArgs); Console.WriteLine(browserStackLocal.isRunning()); } } driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability); //REST API call string reqString = "{\"status\":\"passed\", \"reason\":\"Test Passed\"}"; string sessionId = ((RemoteWebDriver)driver).Capabilities.GetCapability("webdriver.remote.sessionid").ToString(); byte[] requestData = System.Text.Encoding.UTF8.GetBytes(reqString); Uri myUri = new Uri(string.Format($"https://www.browserstack.com/automate/sessions/{sessionId}.json")); System.Net.WebRequest myWebRequest = System.Net.HttpWebRequest.Create(myUri); System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)myWebRequest; myWebRequest.ContentType = "application/json"; myWebRequest.Method = "PUT"; myWebRequest.ContentLength = requestData.Length; using (System.IO.Stream st = myWebRequest.GetRequestStream()) st.Write(requestData, 0, requestData.Length); System.Net.NetworkCredential myNetworkCredential = new NetworkCredential("user", "key"); CredentialCache myCredentialCache = new CredentialCache(); myCredentialCache.Add(myUri, "Basic", myNetworkCredential); myHttpWebRequest.PreAuthenticate = true; myHttpWebRequest.Credentials = myCredentialCache; myWebRequest.GetResponse().Close(); }