Skip to content

Commit e0af937

Browse files
committed
Initial commit with the base page
1 parent 1e1ef0d commit e0af937

File tree

5 files changed

+213
-2
lines changed

5 files changed

+213
-2
lines changed

Automation.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
4+
VisualStudioVersion = 14.0.25123.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Framework", "Framework\Framework.shproj", "{650EBA62-4CA3-4BFC-95DA-6E7920A928A3}"
77
EndProject

Framework/BasePage.cs

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+

2+
namespace Framework
3+
{
4+
internal abstract class BasePage
5+
{
6+
protected readonly IWebDriver Driver;
7+
//Locators to find elements on the page
8+
private readonly By CaseStatusText = By.Id("Body_ctlRegistrationHeader_lblStatus");
9+
10+
protected BasePage(IWebDriver driver)
11+
{
12+
Driver = driver;
13+
}
14+
protected void Visit(string url)
15+
{
16+
if (url.StartsWith("http"))
17+
Driver.Navigate().GoToUrl(url);
18+
else
19+
Driver.Navigate().GoToUrl(BaseTest.ApplicationBaseUrl + url);
20+
}
21+
private IWebElement Find(By locator) => Driver.FindElement(locator);
22+
protected void Click(By locator)
23+
{
24+
Find(locator).Click();
25+
}
26+
protected void EnabledClick(By locator)
27+
{
28+
if(IsEnabled(locator))
29+
Find(locator).Click();
30+
}
31+
protected void Type(By locator, string inputText)
32+
{
33+
Find(locator).SendKeys(inputText);
34+
}
35+
protected void EnabledType(By locator, string inputText)
36+
{
37+
if (IsEnabled(locator))
38+
Find(locator).SendKeys(inputText);
39+
}
40+
protected void DisplayedType(By locator, string inputText)
41+
{
42+
if (IsDisplayed(locator))
43+
Find(locator).SendKeys(inputText);
44+
}
45+
protected void Replace(By locator, string inputText)
46+
{
47+
Find(locator).Clear();
48+
Find(locator).SendKeys(inputText);
49+
}
50+
protected void EnabledReplace(By locator, string inputText)
51+
{
52+
if (IsEnabled(locator))
53+
{
54+
Find(locator).Clear();
55+
Find(locator).SendKeys(inputText);
56+
}
57+
}
58+
protected void DisplayedReplace(By locator, string inputText)
59+
{
60+
if (IsDisplayed(locator))
61+
{
62+
Find(locator).Clear();
63+
Find(locator).SendKeys(inputText);
64+
}
65+
}
66+
protected void Select(By locator, string inputText)
67+
{
68+
new SelectElement(Find(locator)).SelectByText(inputText);
69+
}
70+
protected void EnabledSelect(By locator, string inputText)
71+
{
72+
if (IsEnabled(locator))
73+
new SelectElement(Find(locator)).SelectByText(inputText);
74+
}
75+
protected void DisplayedSelect(By locator, string inputText)
76+
{
77+
if (IsDisplayed(locator))
78+
new SelectElement(Find(locator)).SelectByText(inputText);
79+
}
80+
protected void SelectComboBox(By locator, string inputText)
81+
{
82+
Find(locator).SendKeys(inputText);
83+
Thread.Sleep(1000);
84+
Click(ComboBoxSelection);
85+
}
86+
protected void Check(By locator, string check)
87+
{
88+
if (!string.IsNullOrEmpty(check))
89+
Find(locator).Click();
90+
}
91+
protected void EnabledCheck(By locator, string check)
92+
{
93+
if (IsEnabled(locator))
94+
{
95+
if (!string.IsNullOrEmpty(check))
96+
Find(locator).Click();
97+
}
98+
}
99+
public void SelectAllCheckboxes()
100+
{
101+
IList<IWebElement> ckOverrides = Driver.FindElements(By.XPath("//input[@type='checkbox']"));
102+
103+
foreach (var ck in ckOverrides)
104+
if (ck.Displayed && !ck.Selected)
105+
ck.Click();
106+
}
107+
protected void DeselectAllCheckBoxes()
108+
{
109+
IList<IWebElement> ckOverrides = Driver.FindElements(By.XPath("//input[@type='checkbox']"));
110+
111+
foreach (var ck in ckOverrides)
112+
if (ck.Displayed && ck.Selected)
113+
ck.Click();
114+
}
115+
protected void TabOut(By locator)
116+
{
117+
Type(locator, Keys.Tab);
118+
}
119+
protected bool IsDisplayed(By locator)
120+
{
121+
try
122+
{
123+
return Find(locator).Displayed;
124+
} catch (NoSuchElementException)
125+
{
126+
return false;
127+
}
128+
}
129+
protected bool IsDisplayed(By locator, int maxWaitTime)
130+
{
131+
try
132+
{
133+
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(maxWaitTime));
134+
wait.Until(ExpectedConditions.ElementIsVisible(locator));
135+
return true;
136+
} catch (WebDriverTimeoutException)
137+
{
138+
return false;
139+
}
140+
}
141+
protected bool IsDisplayed(By locator, string text, int maxWaitTime)
142+
{
143+
try
144+
{
145+
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(maxWaitTime));
146+
wait.Until(ExpectedConditions.TextToBePresentInElementValue(locator, text));
147+
return true;
148+
} catch (WebDriverTimeoutException)
149+
{
150+
return false;
151+
}
152+
}
153+
protected bool IsEnabled(By locator)
154+
{
155+
try
156+
{
157+
return Find(locator).Enabled;
158+
} catch (InvalidElementStateException)
159+
{
160+
return false;
161+
}
162+
}
163+
protected void SwitchToFrame(string locator)
164+
{
165+
Driver.SwitchTo().Frame(locator);
166+
}
167+
protected void SwitchToDefaultFrame() => Driver.SwitchTo().DefaultContent();
168+
protected string GetText(By locator)
169+
{
170+
var text = Find(locator);
171+
return text.Text;
172+
}
173+
protected void AcceptPopup()
174+
{
175+
try
176+
{
177+
Driver.SwitchTo().Alert().Accept();
178+
} catch (NoAlertPresentException e) { }
179+
}
180+
}
181+
}

Framework/Framework.projitems

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<Import_RootNamespace>Framework</Import_RootNamespace>
1010
</PropertyGroup>
1111
<ItemGroup>
12+
<Compile Include="$(MSBuildThisFileDirectory)BasePage.cs" />
1213
</ItemGroup>
13-
</Project>
14+
</Project>

UI Tests/UI Tests.csproj

+16
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,35 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
34+
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
35+
<Private>True</Private>
36+
</Reference>
3337
<Reference Include="System" />
3438
<Reference Include="System.Core" />
39+
<Reference Include="System.Drawing" />
3540
<Reference Include="System.Xml.Linq" />
3641
<Reference Include="System.Data.DataSetExtensions" />
3742
<Reference Include="Microsoft.CSharp" />
3843
<Reference Include="System.Data" />
3944
<Reference Include="System.Net.Http" />
4045
<Reference Include="System.Xml" />
46+
<Reference Include="WebDriver, Version=3.4.0.0, Culture=neutral, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Selenium.WebDriver.3.4.0\lib\net40\WebDriver.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="WebDriver.Support, Version=3.4.0.0, Culture=neutral, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Selenium.Support.3.4.0\lib\net40\WebDriver.Support.dll</HintPath>
52+
<Private>True</Private>
53+
</Reference>
4154
</ItemGroup>
4255
<ItemGroup>
4356
<Compile Include="Class1.cs" />
4457
<Compile Include="Properties\AssemblyInfo.cs" />
4558
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="packages.config" />
61+
</ItemGroup>
4662
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4763
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4864
Other similar extension points exist, see Microsoft.Common.targets.

UI Tests/packages.config

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="3.7.1" targetFramework="net461" />
4+
<package id="NUnit.Console" version="3.6.1" targetFramework="net461" />
5+
<package id="NUnit.ConsoleRunner" version="3.6.1" targetFramework="net461" />
6+
<package id="NUnit.Extension.NUnitProjectLoader" version="3.5.0" targetFramework="net461" />
7+
<package id="NUnit.Extension.NUnitV2Driver" version="3.6.0" targetFramework="net461" />
8+
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.5.0" targetFramework="net461" />
9+
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net461" />
10+
<package id="NUnit.Extension.VSProjectLoader" version="3.5.0" targetFramework="net461" />
11+
<package id="Selenium.Support" version="3.4.0" targetFramework="net461" />
12+
<package id="Selenium.WebDriver" version="3.4.0" targetFramework="net461" />
13+
</packages>

0 commit comments

Comments
 (0)