Skip to content

Commit 2a8dff1

Browse files
committed
updated test cases for creating a new post
new post - not working becuase of css selector
1 parent 70f1f05 commit 2a8dff1

File tree

9 files changed

+122
-1
lines changed

9 files changed

+122
-1
lines changed

AutomationFramework.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@
6161
</Otherwise>
6262
</Choose>
6363
<ItemGroup>
64+
<Compile Include="CreatePostsTest.cs" />
6465
<Compile Include="DashboardPage.cs" />
6566
<Compile Include="Driver.cs" />
6667
<Compile Include="LoginPage.cs" />
68+
<Compile Include="NewPostPage.cs" />
69+
<Compile Include="PostPage.cs" />
6770
<Compile Include="UnitTest1.cs" />
6871
<Compile Include="Properties\AssemblyInfo.cs" />
6972
</ItemGroup>

CreatePostsTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace UnitTestProject1
9+
{
10+
[TestClass]
11+
public class CreatePostsTest
12+
{
13+
[TestInitialize]
14+
public void init()
15+
{
16+
Driver.Initialize();
17+
}
18+
[TestMethod]
19+
public void CanCreateBasicPost()
20+
{
21+
LoginPage.GoTo();
22+
LoginPage.LoginAs("scopethesound").WithPassword("niplifeow").Login();
23+
24+
NewPostPage.Goto();
25+
NewPostPage.CreatePost("This is a Test post title").WithBody("Hi,this is the body").Publish();
26+
NewPostPage.GoToNewPost();
27+
Assert.AreEqual(PostPage.Title, "This is a Test post title","The title post did not match");
28+
29+
30+
}
31+
[TestCleanup]
32+
public void Cleanup()
33+
{
34+
//Driver.Close();
35+
}
36+
}
37+
}

Driver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Initialize()
1818

1919
internal static void Close()
2020
{
21-
Instance.Close();
21+
// Instance.Close();
2222

2323
}
2424
}

NewPostPage.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using OpenQA.Selenium;
2+
using System;
3+
using System.Threading;
4+
5+
namespace UnitTestProject1
6+
{
7+
public class NewPostPage
8+
{
9+
public static void Goto()
10+
{
11+
//var menuPosts = Driver.Instance.FindElement(By.ClassName("masterbar__item-content"));
12+
//menuPosts.Click();
13+
var addNew = Driver.Instance.FindElement(By.LinkText("Write"));
14+
addNew.Click();
15+
16+
}
17+
18+
public static CreatePostCommand CreatePost(string title)
19+
20+
{
21+
return new CreatePostCommand(title);
22+
23+
}
24+
25+
public static void GoToNewPost()
26+
{
27+
var message = Driver.Instance.FindElement(By.ClassName("notice__text"));
28+
var newPostLink = Driver.Instance.FindElement(By.XPath("//a[@href='https://ideastechno.wordpress.com/2018/06/22/es/']"));
29+
newPostLink.Click();
30+
}
31+
32+
}
33+
34+
public class CreatePostCommand
35+
{
36+
private string title;
37+
private string body;
38+
39+
public CreatePostCommand(string title)
40+
{
41+
this.title = title;
42+
}
43+
public CreatePostCommand WithBody(string body)
44+
{
45+
this.body = body;
46+
return this;
47+
}
48+
49+
public void Publish()
50+
{
51+
Driver.Instance.FindElement(By.CssSelector("textarea-autosize editor-title__input")).SendKeys(title);
52+
Driver.Instance.FindElement(By.CssSelector(".mce-content-body p")).SendKeys(body);
53+
Thread.Sleep(1000);
54+
Driver.Instance.FindElement(By.ClassName("editor-ground-control__publish-button")).Click();
55+
Driver.Instance.FindElement(By.ClassName("editor-confirmation-sidebar__actionbutton")).Click();
56+
57+
58+
}
59+
60+
61+
}
62+
}

PostPage.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 PostPage
6+
{
7+
public static string Title
8+
{
9+
get
10+
{
11+
var title = Driver.Instance.FindElement(By.ClassName("entry-title"));
12+
if (title != null)
13+
return title.Text;
14+
return "";
15+
16+
}
17+
}
18+
}
19+
}

bin/Debug/UnitTestProject1.dll

2 KB
Binary file not shown.

bin/Debug/UnitTestProject1.pdb

8 KB
Binary file not shown.

obj/Debug/UnitTestProject1.dll

2 KB
Binary file not shown.

obj/Debug/UnitTestProject1.pdb

8 KB
Binary file not shown.

0 commit comments

Comments
 (0)