Skip to content

Commit 5cc4e17

Browse files
authored
Merge pull request #2741 from hardkoded/support-margin-with-no-units
Fix Pdf Margin with no units
2 parents a3cca3a + 188e298 commit 5cc4e17

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
"parameters": ["firefox", "headful"],
7070
"expectations": ["FAIL"]
7171
},
72+
{
73+
"comment": "This is flaky on CI/CD",
74+
"testIdPattern": "[oopif.spec] OOPIF should provide access to elements",
75+
"platforms": ["win32"],
76+
"parameters": ["chrome"],
77+
"expectations": ["FAIL"]
78+
},
7279
{
7380
"comment": "",
7481
"testIdPattern": "[puppeteer-sharp] *",

lib/PuppeteerSharp.Tests/NavigationTests/PageWaitForNavigationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public async Task ShouldWorkWithBothDomcontentloadedAndLoad()
5252
}
5353
}).ContinueWith(_ => bothFired = true);
5454

55-
await waitForRequestTask.WithTimeout();
55+
await waitForRequestTask.WithTimeout(5_000);
5656
await domContentLoadedTask.WithTimeout();
5757
Assert.That(bothFired, Is.False);
5858
responseCompleted.SetResult(true);

lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,27 @@ public void PdfOptionsShouldBeSerializable()
143143
var newPdfOptions = JsonSerializer.Deserialize<PdfOptions>(serialized);
144144
Assert.That(newPdfOptions, Is.EqualTo(pdfOptions));
145145
}
146+
147+
[Test]
148+
public void PdfOptionsShouldWorkWithMarginWithNoUnits()
149+
{
150+
var pdfOptions = new PdfOptions
151+
{
152+
Format = PaperFormat.A4,
153+
DisplayHeaderFooter = true,
154+
MarginOptions = new MarginOptions
155+
{
156+
Top = "0",
157+
Right = "0",
158+
Bottom = "0",
159+
Left = "0"
160+
},
161+
FooterTemplate = "<div id=\"footer-template\" style=\"font-size:10px !important; color:#808080; padding-left:10px\">- <span class=\"pageNumber\"></span> - </div>"
162+
};
163+
164+
var serialized = JsonSerializer.Serialize(pdfOptions);
165+
var newPdfOptions = JsonSerializer.Deserialize<PdfOptions>(serialized);
166+
Assert.That(newPdfOptions, Is.EqualTo(pdfOptions));
167+
}
146168
}
147169
}

lib/PuppeteerSharp/Cdp/CdpPage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,14 +1221,14 @@ private decimal ConvertPrintParameterToInches(object parameter)
12211221
}
12221222

12231223
decimal pixels;
1224-
if (parameter is decimal || parameter is int)
1224+
if (parameter is decimal or int)
12251225
{
12261226
pixels = Convert.ToDecimal(parameter, CultureInfo.CurrentCulture);
12271227
}
12281228
else
12291229
{
12301230
var text = parameter.ToString();
1231-
var unit = text.Substring(text.Length - 2).ToLower(CultureInfo.CurrentCulture);
1231+
var unit = text.Length > 2 ? text.Substring(text.Length - 2).ToLower(CultureInfo.CurrentCulture) : string.Empty;
12321232
string valueText;
12331233
if (_unitToPixels.ContainsKey(unit))
12341234
{

0 commit comments

Comments
 (0)