had to upgrade to the Selenium 4 alpha to get this to work
This commit is contained in:
parent
63606a3970
commit
2e71327e04
66
weehawken/BrowserDriver.cs
Normal file
66
weehawken/BrowserDriver.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using OpenQA.Selenium.Chrome;
|
||||||
|
using OpenQA.Selenium.Edge;
|
||||||
|
using OpenQA.Selenium.Firefox;
|
||||||
|
using OpenQA.Selenium.Remote;
|
||||||
|
using OpenQA.Selenium.Safari;
|
||||||
|
|
||||||
|
namespace weehawken
|
||||||
|
{
|
||||||
|
public static class BrowserDriver
|
||||||
|
{
|
||||||
|
public static RemoteWebDriver GetDriver(string browser, bool headless)
|
||||||
|
{
|
||||||
|
switch (browser)
|
||||||
|
{
|
||||||
|
case "chrome":
|
||||||
|
return GetChrome(headless);
|
||||||
|
case "firefox":
|
||||||
|
return GetFirefox(headless);
|
||||||
|
case "safari":
|
||||||
|
return getSafari(headless);
|
||||||
|
case "edge":
|
||||||
|
return getEdge(headless);
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Invalid browser specified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static RemoteWebDriver GetChrome(bool headless)
|
||||||
|
{
|
||||||
|
ChromeOptions opts = new ChromeOptions();
|
||||||
|
if (headless)
|
||||||
|
{
|
||||||
|
opts.AddArguments("headless");
|
||||||
|
}
|
||||||
|
opts.AcceptInsecureCertificates = true;
|
||||||
|
RemoteWebDriver driver = new ChromeDriver(opts);
|
||||||
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RemoteWebDriver GetFirefox(bool headless)
|
||||||
|
{
|
||||||
|
FirefoxOptions fopts = new FirefoxOptions();
|
||||||
|
if (headless)
|
||||||
|
{
|
||||||
|
fopts.AddArguments("--headless");
|
||||||
|
}
|
||||||
|
fopts.AcceptInsecureCertificates = true;
|
||||||
|
RemoteWebDriver driver = new FirefoxDriver(fopts);
|
||||||
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RemoteWebDriver getSafari(bool headless)
|
||||||
|
{
|
||||||
|
return new SafariDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RemoteWebDriver getEdge(bool headless)
|
||||||
|
{
|
||||||
|
return new EdgeDriver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using OpenQA.Selenium;
|
using OpenQA.Selenium;
|
||||||
using OpenQA.Selenium.Chrome;
|
|
||||||
using OpenQA.Selenium.Firefox;
|
using OpenQA.Selenium.Firefox;
|
||||||
using OpenQA.Selenium.Remote;
|
using OpenQA.Selenium.Remote;
|
||||||
|
|
||||||
@ -9,56 +8,51 @@ namespace weehawken
|
|||||||
{
|
{
|
||||||
public class Tests
|
public class Tests
|
||||||
{
|
{
|
||||||
ChromeDriver chromeDriver;
|
private String url;
|
||||||
FirefoxDriver firefoxDriver;
|
private RemoteWebDriver driver;
|
||||||
String url = "https://duckduckgo.com/";
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Beginning Test");
|
Console.WriteLine("Beginning Test");
|
||||||
|
url = "https://duckduckgo.com/";
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
|
driver.Quit();
|
||||||
Console.WriteLine("End Test");
|
Console.WriteLine("End Test");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ChromeTest()
|
public void ChromeTest()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Chrome Test");
|
Console.WriteLine("Chrome Test");
|
||||||
ChromeOptions copts = new ChromeOptions();
|
driver = BrowserDriver.GetDriver("chrome", true);
|
||||||
copts.AddArguments("headless");
|
driver.Navigate().GoToUrl(url);
|
||||||
chromeDriver = new ChromeDriver(copts);
|
|
||||||
chromeDriver.Navigate().GoToUrl(url);
|
|
||||||
RemoteWebElement searchBox =
|
RemoteWebElement searchBox =
|
||||||
(RemoteWebElement)chromeDriver.FindElementByXPath("//input[@id='search_form_input_homepage']");
|
(RemoteWebElement)driver.FindElementByXPath("//input[@id='search_form_input_homepage']");
|
||||||
searchBox.SendKeys("frankenberries");
|
searchBox.SendKeys("frankenberries");
|
||||||
searchBox.SendKeys(Keys.Enter);
|
searchBox.SendKeys(Keys.Enter);
|
||||||
RemoteWebElement results =
|
RemoteWebElement results =
|
||||||
(RemoteWebElement)chromeDriver.FindElementByPartialLinkText("Monster cereal");
|
(RemoteWebElement)driver.FindElementByPartialLinkText("Monster cereal");
|
||||||
Assert.NotNull(results);
|
Assert.NotNull(results);
|
||||||
chromeDriver.Quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FirefoxTest()
|
public void FirefoxTest()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Firefox Test");
|
Console.WriteLine("Firefox Test");
|
||||||
FirefoxOptions fopts = new FirefoxOptions();
|
driver = BrowserDriver.GetDriver("firefox", true);
|
||||||
fopts.AddArguments("--headless");
|
driver.Navigate().GoToUrl(url);
|
||||||
firefoxDriver = new FirefoxDriver(fopts);
|
driver.FindElementByXPath("//input[@id='search_form_input_homepage']")
|
||||||
firefoxDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
|
|
||||||
firefoxDriver.Navigate().GoToUrl(url);
|
|
||||||
firefoxDriver.FindElementByXPath("//input[@id='search_form_input_homepage']")
|
|
||||||
.SendKeys("frankenberries" + Keys.Enter);
|
.SendKeys("frankenberries" + Keys.Enter);
|
||||||
|
|
||||||
RemoteWebElement results =
|
RemoteWebElement results =
|
||||||
(RemoteWebElement)firefoxDriver.FindElementByPartialLinkText("Monster cereal");
|
(RemoteWebElement)driver.FindElementByPartialLinkText("Monster cereal");
|
||||||
Assert.NotNull(results);
|
Assert.NotNull(results);
|
||||||
firefoxDriver.Quit();
|
driver.Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
4
weehawken/README.md
Normal file
4
weehawken/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# WEEHAWKEN C# TEST FRAMEWORK
|
||||||
|
|
||||||
|
This framework is basically a clone port of my java framework. It's a work in progress.
|
||||||
|
|
@ -10,8 +10,8 @@
|
|||||||
<PackageReference Include="nunit" Version="3.12.0" />
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
|
<PackageReference Include="Selenium.WebDriver" Version="4.0.0-alpha05" />
|
||||||
<PackageReference Include="Selenium.Support" Version="3.141.0" />
|
<PackageReference Include="Selenium.Support" Version="4.0.0-alpha05" />
|
||||||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="86.0.4240.2200" />
|
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="86.0.4240.2200" />
|
||||||
<PackageReference Include="Selenium.WebDriver.IEDriver" Version="3.150.1.2" />
|
<PackageReference Include="Selenium.WebDriver.IEDriver" Version="3.150.1.2" />
|
||||||
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.27.0" />
|
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.27.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user