Skip to content

Commit 073bc19

Browse files
committed
selenium framework
started some basic smoke tests
1 parent 75ab601 commit 073bc19

24 files changed

+17248
-0
lines changed

AutomationFramework.csproj

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{FC3F5071-1547-4D8F-A1D7-34ECF2A7D39E}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>UnitTestProject1</RootNamespace>
10+
<AssemblyName>UnitTestProject1</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
<NuGetPackageImportStamp>
20+
</NuGetPackageImportStamp>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>full</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug\</OutputPath>
27+
<DefineConstants>DEBUG;TRACE</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="System" />
41+
<Reference Include="System.Drawing" />
42+
<Reference Include="WebDriver, Version=3.12.1.0, Culture=neutral, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Selenium.WebDriver.3.12.1\lib\net45\WebDriver.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="WebDriver.Support, Version=3.12.1.0, Culture=neutral, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Selenium.Support.3.12.1\lib\net45\WebDriver.Support.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
</ItemGroup>
51+
<Choose>
52+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
53+
<ItemGroup>
54+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
55+
</ItemGroup>
56+
</When>
57+
<Otherwise>
58+
<ItemGroup>
59+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
60+
</ItemGroup>
61+
</Otherwise>
62+
</Choose>
63+
<ItemGroup>
64+
<Compile Include="DashboardPage.cs" />
65+
<Compile Include="Driver.cs" />
66+
<Compile Include="LoginPage.cs" />
67+
<Compile Include="UnitTest1.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="packages.config" />
72+
</ItemGroup>
73+
<Choose>
74+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
75+
<ItemGroup>
76+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
77+
<Private>False</Private>
78+
</Reference>
79+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
80+
<Private>False</Private>
81+
</Reference>
82+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
83+
<Private>False</Private>
84+
</Reference>
85+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
86+
<Private>False</Private>
87+
</Reference>
88+
</ItemGroup>
89+
</When>
90+
</Choose>
91+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
<Import Project="..\packages\Selenium.Firefox.WebDriver.0.21.0\build\Selenium.Firefox.WebDriver.targets" Condition="Exists('..\packages\Selenium.Firefox.WebDriver.0.21.0\build\Selenium.Firefox.WebDriver.targets')" />
94+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
95+
<PropertyGroup>
96+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
97+
</PropertyGroup>
98+
<Error Condition="!Exists('..\packages\Selenium.Firefox.WebDriver.0.21.0\build\Selenium.Firefox.WebDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.Firefox.WebDriver.0.21.0\build\Selenium.Firefox.WebDriver.targets'))" />
99+
</Target>
100+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
101+
Other similar extension points exist, see Microsoft.Common.targets.
102+
<Target Name="BeforeBuild">
103+
</Target>
104+
<Target Name="AfterBuild">
105+
</Target>
106+
-->
107+
</Project>

DashboardPage.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using OpenQA.Selenium;
2+
3+
namespace UnitTestProject1
4+
{
5+
public class DashboardPage
6+
{
7+
public static bool IsAt
8+
{
9+
get
10+
{
11+
var h1s = Driver.Instance.FindElements(By.ClassName("menu-link-text"));
12+
if (h1s.Count > 0)
13+
return h1s[0].Text == "Followed Sites";
14+
return false;
15+
16+
}
17+
}
18+
}
19+
}

Driver.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Firefox;
3+
using System;
4+
5+
namespace UnitTestProject1
6+
{
7+
public class Driver
8+
{
9+
public static IWebDriver Instance
10+
{
11+
get; set;
12+
}
13+
public static void Initialize()
14+
{
15+
Instance = new FirefoxDriver();
16+
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
17+
}
18+
19+
internal static void Close()
20+
{
21+
Instance.Close();
22+
23+
}
24+
}
25+
}

LoginPage.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Firefox;
3+
using OpenQA.Selenium.Support.UI;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace UnitTestProject1
11+
{
12+
public class LoginPage
13+
{
14+
public static void GoTo()
15+
{
16+
17+
18+
Driver.Instance.Navigate().GoToUrl("https://wordpress.com/log-in?redirect_to=https%3A%2F%2Fwordpress.com%2F");
19+
var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
20+
wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == "usernameOrEmail");
21+
}
22+
public static LoginCommand LoginAs(string userName)
23+
{
24+
return new LoginCommand(userName);
25+
}
26+
27+
28+
public class LoginCommand
29+
{
30+
private readonly string userName;
31+
private string password;
32+
public LoginCommand(string userName)
33+
{
34+
this.userName = userName;
35+
}
36+
37+
public LoginCommand WithPassword(string password)
38+
{
39+
this.password = password;
40+
return this;
41+
42+
}
43+
44+
public void Login()
45+
{
46+
var loginInput = Driver.Instance.FindElement(By.Id("usernameOrEmail"));
47+
loginInput.SendKeys(userName);
48+
49+
var ContinueButton = Driver.Instance.FindElement(By.CssSelector("button.is-primary"));
50+
ContinueButton.Click();
51+
52+
var passwordInput = Driver.Instance.FindElement(By.Id("password"));
53+
passwordInput.SendKeys(password);
54+
55+
var loginButton = Driver.Instance.FindElement(By.CssSelector("button"));
56+
loginButton.Click();
57+
58+
59+
60+
}
61+
62+
}
63+
}
64+
65+
}

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("UnitTestProject1")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("UnitTestProject1")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("fc3f5071-1547-4d8f-a1d7-34ecf2a7d39e")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

UnitTest1.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace UnitTestProject1
5+
{
6+
[TestClass]
7+
public class UnitTest1
8+
{
9+
10+
[TestInitialize]
11+
public void init()
12+
{
13+
Driver.Initialize();
14+
}
15+
[TestMethod]
16+
public void TestMethod1()
17+
{
18+
LoginPage.GoTo();
19+
LoginPage.LoginAs("scopethesound").WithPassword("niplifeow").Login();
20+
Assert.IsTrue(DashboardPage.IsAt, "Failed to login");
21+
22+
}
23+
[TestCleanup]
24+
public void Cleanup()
25+
{
26+
Driver.Close();
27+
}
28+
}
29+
}
Binary file not shown.

0 commit comments

Comments
 (0)