View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void FocusOnControl() | |
{ | |
this.driver.Navigate().GoToUrl( | |
@"http://automatetheplanet.com/compelling-sunday-14022016/"); | |
IWebElement link = driver.FindElement(By.PartialLinkText("Previous post")); | |
// 9.1. Option 1. | |
link.SendKeys(string.Empty); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void ScrollFocusToControl() | |
{ | |
this.driver.Navigate().GoToUrl(@"http://automatetheplanet.com/compelling-sunday-14022016/"); | |
IWebElement link = driver.FindElement(By.PartialLinkText("Previous post")); | |
string jsToBeExecuted = string.Format("window.scroll(0, {0});", link.Location.Y); | |
((IJavaScriptExecutor)driver).ExecuteScript(jsToBeExecuted); | |
link.Click(); | |
Assert.AreEqual<string>("10 Advanced WebDriver Tips and Tricks - Part 1", driver.Title); | |
} |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DesiredCapabilities capability = DesiredCapabilities.InternetExplorer(); | |
Environment.SetEnvironmentVariable("webdriver.ie.driver", "C:\\Path\\To\\IEDriver.exe"); | |
capability.SetCapability(CapabilityType.AcceptSslCertificates, true); | |
driver = new RemoteWebDriver(capability); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DesiredCapabilities capability = DesiredCapabilities.Chrome(); | |
Environment.SetEnvironmentVariable("webdriver.chrome.driver", "C:\\Path\\To\\ChromeDriver.exe"); | |
capability.SetCapability(CapabilityType.AcceptSslCertificates, true); | |
driver = new RemoteWebDriver(capability); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FirefoxProfile firefoxProfile = new FirefoxProfile(); | |
firefoxProfile.AcceptUntrustedCertificates = true; | |
firefoxProfile.AssumeUntrustedCertificateIssuer = false; | |
driver = new FirefoxDriver(firefoxProfile); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FirefoxProfile firefoxProfile = new FirefoxProfile(); | |
firefoxProfile.SetPreference("network.proxy.type", 1); | |
firefoxProfile.SetPreference("network.proxy.http", "myproxy.com"); | |
firefoxProfile.SetPreference("network.proxy.http_port", 3239); | |
driver = new FirefoxDriver(firefoxProfile); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FirefoxProfileManager profileManager = new FirefoxProfileManager(); | |
FirefoxProfile profile = new FirefoxProfile(); | |
profile.SetPreference( | |
"general.useragent.override", | |
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+"); | |
this.driver = new FirefoxDriver(profile); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void FileUpload() | |
{ | |
this.driver.Navigate().GoToUrl( | |
@"https://demos.telerik.com/aspnet-ajax/ajaxpanel/application-scenarios/file-upload/defaultcs.aspx"); | |
IWebElement element = | |
driver.FindElement(By.Id("ctl00_ContentPlaceholder1_RadUpload1file0")); | |
String filePath = | |
@"D:\Projects\PatternsInAutomation.Tests\WebDriver.Series.Tests\bin\Debug\WebDriver.xml"; | |
element.SendKeys(filePath); |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void NavigationHistory() | |
{ | |
this.driver.Navigate().GoToUrl( | |
@"http://www.codeproject.com/Articles/1078541/Advanced-WebDriver-Tips-and-Tricks-Part"); | |
this.driver.Navigate().GoToUrl( | |
@"http://www.codeproject.com/Articles/1017816/Speed-up-Selenium-Tests-through-RAM-Facts-and-Myth"); | |
driver.Navigate().Back(); | |
Assert.AreEqual<string>( | |
"10 Advanced WebDriver Tips and Tricks - Part 1 - CodeProject", |
View AdvancedWebDriverUsageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void MovingBetweenTabs() | |
{ | |
this.driver.Navigate().GoToUrl(@"http://automatetheplanet.com/compelling-sunday-14022016/"); | |
driver.FindElement(By.LinkText("10 Advanced WebDriver Tips and Tricks Part 1")).Click(); | |
driver.FindElement(By.LinkText("The Ultimate Guide To Unit Testing in ASP.NET MVC")).Click(); | |
ReadOnlyCollection<String> windowHandles = driver.WindowHandles; | |
String firstTab = windowHandles.First(); | |
String lastTab = windowHandles.Last(); | |
driver.SwitchTo().Window(lastTab); |
NewerOlder