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

Allow partial comparison #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions src/main/java/com/testautomationguru/utility/PDFUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ private boolean comparePdfByImage(String file1, String file2, int startPage, int

int pgCount1 = this.getPageCount(file1);
int pgCount2 = this.getPageCount(file2);
if(pgCount1!=pgCount2){
logger.warning("files page counts do not match - returning false");

if(!isPartialComparisonPossible(pgCount1, pgCount2, endPage)){
logger.warning("partial comparison not possible - returning false");
return false;
}

Expand All @@ -457,6 +457,23 @@ private boolean comparePdfByImage(String file1, String file2, int startPage, int
return this.convertToImageAndCompare(file1, file2, this.startPage, this.endPage);
}


private boolean isPartialComparisonPossible(int pageCountFile1, int pageCountFile2, int endPage) {

if (pageCountFile1 != pageCountFile2) {
logger.warning("files page counts do not match");
boolean isPartialComparisonPossible = pageCountFile1 >= endPage && pageCountFile2 >= endPage;
if (isPartialComparisonPossible) {
logger.warning("partial comparison possible");
return true;
} else {
return false;
}
} else {
return true;
}
}

private boolean convertToImageAndCompare(String file1, String file2, int startPage, int endPage) throws IOException{

boolean result = true;
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/testautomationguru/utility/PDFUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ public void comparePDFImageModeDiffSpecificPage() throws IOException {
Assert.assertTrue(result);
}

@Test(priority = 11)
public void comparePDFImageModePartial() throws IOException {
String file1 = getFilePath("image-compare-partial/sample1.pdf");
String file2 = getFilePath("image-compare-partial/sample2.pdf");
pdfutil.setCompareMode(CompareMode.VISUAL_MODE);

boolean result = pdfutil.compare(file1, file2, 1, 1);
Assert.assertTrue(result);
}

@Test(priority = 12)
public void comparePDFImageModePartialNotPossible() throws IOException {
String file1 = getFilePath("image-compare-partial/sample1.pdf");
String file2 = getFilePath("image-compare-partial/sample2.pdf");
pdfutil.setCompareMode(CompareMode.VISUAL_MODE);

boolean result = pdfutil.compare(file1, file2, 1, 2);
Assert.assertFalse(result);
}

private String getFilePath(String filename) {
return new File(getClass().getClassLoader().getResource(filename).getFile()).getAbsolutePath();
}
Expand Down
Binary file not shown.
Binary file not shown.