Skip to content

Instantly share code, notes, and snippets.

View angelovstanton's full-sized avatar
💭
UPDATED STATUS

Anton Angelov angelovstanton

💭
UPDATED STATUS
View GitHub Profile
[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);
[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);
}
DesiredCapabilities capability = DesiredCapabilities.InternetExplorer();
Environment.SetEnvironmentVariable("webdriver.ie.driver", "C:\\Path\\To\\IEDriver.exe");
capability.SetCapability(CapabilityType.AcceptSslCertificates, true);
driver = new RemoteWebDriver(capability);
DesiredCapabilities capability = DesiredCapabilities.Chrome();
Environment.SetEnvironmentVariable("webdriver.chrome.driver", "C:\\Path\\To\\ChromeDriver.exe");
capability.SetCapability(CapabilityType.AcceptSslCertificates, true);
driver = new RemoteWebDriver(capability);
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.AcceptUntrustedCertificates = true;
firefoxProfile.AssumeUntrustedCertificateIssuer = false;
driver = new FirefoxDriver(firefoxProfile);
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);
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);
[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);
[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",
[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);