Skip to content

Commit 4f59b68

Browse files
authored
Add default context cookies test (#1286)
* Add default context cookies test * Add missing facts * Add test collection constant * Fix replace * cr * cr * code factor
1 parent 0f73456 commit 4f59b68

File tree

140 files changed

+245
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+245
-139
lines changed

lib/PuppeteerSharp.Tests/AccessibilityTests/AccessibilityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace PuppeteerSharp.Tests.AccesibilityTests
77
{
8-
[Collection("PuppeteerLoaderFixture collection")]
8+
[Collection(TestConstants.TestFixtureCollectionName)]
99
public class AccesibilityTests : PuppeteerPageBaseTest
1010
{
1111
public AccesibilityTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/AccessibilityTests/RootOptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace PuppeteerSharp.Tests.AccesibilityTests
77
{
8-
[Collection("PuppeteerLoaderFixture collection")]
8+
[Collection(TestConstants.TestFixtureCollectionName)]
99
public class RootOptionTests : PuppeteerPageBaseTest
1010
{
1111
public RootOptionTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/BrowserContextTests/BrowserContextTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace PuppeteerSharp.Tests.BrowserContextTests
1010
{
11-
[Collection("PuppeteerLoaderFixture collection")]
11+
[Collection(TestConstants.TestFixtureCollectionName)]
1212
public class BrowserContextTests : PuppeteerBrowserBaseTest
1313
{
1414
public BrowserContextTests(ITestOutputHelper output) : base(output)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
9+
namespace PuppeteerSharp.Tests.BrowserContextTests
10+
{
11+
[Collection(TestConstants.TestFixtureCollectionName)]
12+
public class DefaultBrowserContextTests : PuppeteerPageBaseTest
13+
{
14+
public DefaultBrowserContextTests(ITestOutputHelper output) : base(output)
15+
{
16+
}
17+
18+
public override async Task InitializeAsync()
19+
{
20+
await base.InitializeAsync();
21+
22+
Context = Browser.DefaultContext;
23+
Page = await Context.NewPageAsync();
24+
}
25+
26+
[Fact]
27+
public async Task PageGetCookiesAsyncShouldWork()
28+
{
29+
await Page.GoToAsync(TestConstants.EmptyPage);
30+
31+
await Page.EvaluateExpressionAsync("document.cookie = 'username=John Doe'");
32+
var cookie = (await Page.GetCookiesAsync()).FirstOrDefault();
33+
Assert.Equal("username", cookie.Name);
34+
Assert.Equal("John Doe", cookie.Value);
35+
Assert.Equal("localhost", cookie.Domain);
36+
Assert.Equal("/", cookie.Path);
37+
Assert.Equal(-1, cookie.Expires);
38+
Assert.Equal(16, cookie.Size);
39+
Assert.False(cookie.HttpOnly);
40+
Assert.False(cookie.Secure);
41+
Assert.True(cookie.Session);
42+
}
43+
44+
[Fact]
45+
public async Task PageSetCookiesAsyncShouldWork()
46+
{
47+
await Page.GoToAsync(TestConstants.EmptyPage);
48+
49+
await Page.SetCookieAsync(new CookieParam
50+
{
51+
Name = "username",
52+
Value = "John Doe"
53+
});
54+
55+
var cookie = (await Page.GetCookiesAsync()).FirstOrDefault();
56+
Assert.Equal("username", cookie.Name);
57+
Assert.Equal("John Doe", cookie.Value);
58+
Assert.Equal("localhost", cookie.Domain);
59+
Assert.Equal("/", cookie.Path);
60+
Assert.Equal(-1, cookie.Expires);
61+
Assert.Equal(16, cookie.Size);
62+
Assert.False(cookie.HttpOnly);
63+
Assert.False(cookie.Secure);
64+
Assert.True(cookie.Session);
65+
}
66+
67+
[Fact]
68+
public async Task PageDeleteCookieAsyncShouldWork()
69+
{
70+
await Page.GoToAsync(TestConstants.EmptyPage);
71+
72+
await Page.SetCookieAsync(
73+
new CookieParam
74+
{
75+
Name = "cookie1",
76+
Value = "1"
77+
},
78+
new CookieParam
79+
{
80+
Name = "cookie2",
81+
Value = "2"
82+
});
83+
84+
Assert.Equal("cookie1=1; cookie2=2", await Page.EvaluateExpressionAsync<string>("document.cookie"));
85+
await Page.DeleteCookieAsync(new CookieParam
86+
{
87+
Name = "cookie2"
88+
});
89+
Assert.Equal("cookie1=1", await Page.EvaluateExpressionAsync<string>("document.cookie"));
90+
91+
var cookie = (await Page.GetCookiesAsync()).FirstOrDefault();
92+
Assert.Equal("cookie1", cookie.Name);
93+
Assert.Equal("1", cookie.Value);
94+
Assert.Equal("localhost", cookie.Domain);
95+
Assert.Equal("/", cookie.Path);
96+
Assert.Equal(-1, cookie.Expires);
97+
Assert.Equal(8, cookie.Size);
98+
Assert.False(cookie.HttpOnly);
99+
Assert.False(cookie.Secure);
100+
Assert.True(cookie.Session);
101+
}
102+
}
103+
}

lib/PuppeteerSharp.Tests/BrowserTests/Events/TargetTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace PuppeteerSharp.Tests.BrowserTests.Events
1010
{
11-
[Collection("PuppeteerLoaderFixture collection")]
11+
[Collection(TestConstants.TestFixtureCollectionName)]
1212
public class TargetTests : PuppeteerBrowserBaseTest
1313
{
1414
public TargetTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/BrowserTests/IsConnectedTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PuppeteerSharp.Tests.BrowserTests
66
{
7-
[Collection("PuppeteerLoaderFixture collection")]
7+
[Collection(TestConstants.TestFixtureCollectionName)]
88
public class IsConnectedTests : PuppeteerBrowserBaseTest
99
{
1010
public IsConnectedTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/BrowserTests/ProcessTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PuppeteerSharp.Tests.BrowserTests
66
{
7-
[Collection("PuppeteerLoaderFixture collection")]
7+
[Collection(TestConstants.TestFixtureCollectionName)]
88
public class ProcessTests : PuppeteerBrowserBaseTest
99
{
1010
public ProcessTests(ITestOutputHelper output) : base(output) { }

lib/PuppeteerSharp.Tests/BrowserTests/TargetTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PuppeteerSharp.Tests.BrowserTests
66
{
7-
[Collection("PuppeteerLoaderFixture collection")]
7+
[Collection(TestConstants.TestFixtureCollectionName)]
88
public class TargetTests : PuppeteerBrowserBaseTest
99
{
1010
public TargetTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/BrowserTests/UserAgentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PuppeteerSharp.Tests.BrowserTests
66
{
7-
[Collection("PuppeteerLoaderFixture collection")]
7+
[Collection(TestConstants.TestFixtureCollectionName)]
88
public class UserAgentTests : PuppeteerBrowserBaseTest
99
{
1010
public UserAgentTests(ITestOutputHelper output) : base(output)

lib/PuppeteerSharp.Tests/BrowserTests/VersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PuppeteerSharp.Tests.BrowserTests
66
{
7-
[Collection("PuppeteerLoaderFixture collection")]
7+
[Collection(TestConstants.TestFixtureCollectionName)]
88
public class VersionTests : PuppeteerBrowserBaseTest
99
{
1010
public VersionTests(ITestOutputHelper output) : base(output)

0 commit comments

Comments
 (0)