Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Enhance PageSize class to support for predefined and custom Paper Sizes #15052

Merged
merged 27 commits into from
Jan 23, 2025
Merged
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
40fd006
Enhance PageSize class to support for predefined and custom Paper Sizes
yvsvarma Jan 9, 2025
270717d
Addressed review comments by updating PageSize constants for direct r…
yvsvarma Jan 11, 2025
f24cf74
added comment on units for the pagesize
yvsvarma Jan 11, 2025
5efe4f8
Updating PageSizeTest to verify new PageSize constants and functionality
yvsvarma Jan 12, 2025
91ee7f4
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 12, 2025
569f9d1
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 12, 2025
c1a7eb3
addressing review comments
yvsvarma Jan 13, 2025
520b8e1
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 15, 2025
a0d57be
Addressed review comments: Added prefixed constants to PageSize and u…
yvsvarma Jan 15, 2025
896791e
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 16, 2025
5ed619d
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 16, 2025
0eae862
Merge branch 'trunk' into print-page-size-options
pujagani Jan 16, 2025
0ee9e1b
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 17, 2025
96c3073
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 18, 2025
bd8bfa9
updating after format.sh run
yvsvarma Jan 18, 2025
a1b98b2
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 18, 2025
f94a814
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 19, 2025
23cc376
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 19, 2025
ed745a6
Merge branch 'trunk' into print-page-size-options
VietND96 Jan 19, 2025
608e4ba
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 20, 2025
9df94fa
Merge branch 'trunk' into print-page-size-options
VietND96 Jan 20, 2025
1194a13
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 21, 2025
100f9ee
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 22, 2025
4d367b2
addressing review comments to simplify accessing pagesize
yvsvarma Jan 22, 2025
6cbb99c
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 23, 2025
f5f6d5a
Update PageSizeTest.java
pujagani Jan 23, 2025
50a0547
Merge branch 'trunk' into print-page-size-options
yvsvarma Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions java/src/org/openqa/selenium/print/PageSize.java
Original file line number Diff line number Diff line change
@@ -23,15 +23,19 @@

@NullMarked
public class PageSize {

private final double height;
private final double width;

// Reference for predefined page size constants: https://www.agooddaytoprint.com/page/paper-size-chart-faq
public static final PageSize ISO_A4 = new PageSize(29.7, 21.0); // ISO_A4 size in cm
public static final PageSize US_LEGAL = new PageSize(35.56, 21.59); // US_LEGAL size in cm
public static final PageSize ANSI_TABLOID = new PageSize(43.18, 27.94); // ANSI_TABLOID size in cm
public static final PageSize US_LETTER = new PageSize(27.94, 21.59); // US_LETTER size in cm

public PageSize() {
// Initialize with defaults. A4 paper size defaults in cms.
this.height = 27.94;
this.width = 21.59;
}
// Initialize with defaults. ISO_A4 paper size defaults in cms.
this(ISO_A4.getHeight(), ISO_A4.getWidth());
}

public PageSize(double height, double width) {
this.height = height;
@@ -46,11 +50,24 @@ public double getWidth() {
return width;
}

public static PageSize setPageSize(PageSize pageSize) {
if (pageSize == null) {
throw new IllegalArgumentException("Page size cannot be null");
}
return new PageSize(pageSize.getHeight(), pageSize.getWidth());
}

public Map<String, Object> toMap() {
final Map<String, Object> options = new HashMap<>(7);
options.put("height", getHeight());
options.put("width", getWidth());

return options;
}
}

@Override
public String toString() {
return "PageSize[width=" + this.getWidth() + ", height=" + this.getHeight() + "]";
}

}
41 changes: 32 additions & 9 deletions java/test/org/openqa/selenium/print/PageSizeTest.java
Original file line number Diff line number Diff line change
@@ -25,15 +25,38 @@
@Tag("UnitTests")
class PageSizeTest {

// Defaults assertion
private static final double HEIGHT = 27.94;
private static final double WIDTH = 21.59;

@Test
void setsDefaultHeightWidth() {
@Test
void setsDefaultHeightWidth() {
PageSize pageSize = new PageSize();
assertThat(pageSize.getHeight()).isEqualTo(29.7);
assertThat(pageSize.getWidth()).isEqualTo(21.0);
}

@Test
void verifiesPageSizeA4() {
PageSize pageSize = PageSize.setPageSize(PageSize.ISO_A4);
assertThat(pageSize.getHeight()).isEqualTo(29.7);
assertThat(pageSize.getWidth()).isEqualTo(21.0);
}

@Test
void verifiesPageSizeLegal() {
PageSize pageSize = PageSize.setPageSize(PageSize.US_LEGAL);
assertThat(pageSize.getHeight()).isEqualTo(35.56);
assertThat(pageSize.getWidth()).isEqualTo(21.59);
}

@Test
void verifiesPageSizeLetter() {
PageSize pageSize = PageSize.setPageSize(PageSize.US_LETTER);
assertThat(pageSize.getHeight()).isEqualTo(27.94);
assertThat(pageSize.getWidth()).isEqualTo(21.59);
}

assertThat(pageSize.getHeight()).isEqualTo(HEIGHT);
assertThat(pageSize.getWidth()).isEqualTo(WIDTH);
@Test
void verifiesPageSizeTabloid() {
PageSize pageSize = PageSize.setPageSize(PageSize.ANSI_TABLOID);
assertThat(pageSize.getHeight()).isEqualTo(43.18);
assertThat(pageSize.getWidth()).isEqualTo(27.94);
}
}
}