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

[stable-3.28] Scanbot functionality #140

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 16 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ android {
// see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
packagingOptions {
resources {
excludes += 'META-INF/LICENSE*'
excludes += ['META-INF/LICENSE*', 'META-INF/DEPENDENCIES']
pickFirst 'MANIFEST.MF' // workaround for duplicated manifest on some dependencies
}
}
Expand Down Expand Up @@ -262,7 +262,9 @@ dependencies {
implementation "androidx.fragment:fragment-ktx:1.6.1"
implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
implementation 'commons-io:commons-io:2.13.0'
//Note: Do not change the commons-io:commons-io version from 2.4 to any other
//this is required for ScanBot SDK to work on low end devices ie. 6 & 7 Api levels
implementation 'commons-io:commons-io:2.4'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.12.0'
implementation 'org.lukhnos:nnio:0.2'
Expand All @@ -283,10 +285,11 @@ dependencies {
implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido:$fidoVersion"
implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido2:$fidoVersion"

//NextCloud scan is not required in NMC
// document scanner not available on FDroid (generic) due to OpenCV binaries
gplayImplementation project(':appscan')
huaweiImplementation project(':appscan')
qaImplementation project(':appscan')
/* gplayImplementation project(':appscan')
huaweiImplementation project(':appscan')
qaImplementation project(':appscan') */

spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.6.0'
Expand Down Expand Up @@ -392,6 +395,14 @@ dependencies {

// splash screen dependency ref: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
implementation 'androidx.core:core-splashscreen:1.0.1'

//scanbot sdk: https://github.com/doo/scanbot-sdk-example-android
implementation "io.scanbot:sdk-package-2:$scanbotSdkVersion"

//apache pdf-box for encrypting pdf files
implementation(group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.1') {
exclude group: "commons-logging"
}
}

configurations.configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.nmc.android;

import android.Manifest;

import com.nmc.android.ui.ScanActivity;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.GrantPermissionRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.core.IsNot.not;

@RunWith(AndroidJUnit4.class)
@LargeTest
/**
* Scan test to test the max number of possible scans till device throws exception or unexpected error occurs
*/
public class ScanActivityMultipleTest extends AbstractIT {

@Rule public ActivityScenarioRule<ScanActivity> activityRule = new ActivityScenarioRule<>(ScanActivity.class);

@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.CAMERA);

/**
* variable to define max number of scans to test
*/
private static final int MAX_NUMBER_OF_SCAN = 40;
private int docScanCount = 0;

@Test
public void runAllScanTests() {
captureAndVerifyDocScan();
for (int i=0;i<MAX_NUMBER_OF_SCAN;i++) {
System.out.println("Scan no: "+docScanCount);
verifyScanMoreDocument();
}
}

public void captureAndVerifyDocScan() {
onView(withId(R.id.shutterButton)).perform(click());
shortSleep();
shortSleep();
shortSleep();
shortSleep();
docScanCount++;
assertEquals(docScanCount, ScanActivity.originalScannedImages.size());
}

public void verifyScanMoreDocument() {
onView(withId(R.id.scanMoreButton)).perform(click());
captureAndVerifyDocScan();
}
}
201 changes: 201 additions & 0 deletions app/src/androidTest/java/com/nmc/android/ScanActivityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package com.nmc.android;

import android.Manifest;

import com.nmc.android.ui.ScanActivity;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.GrantPermissionRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.hasTextColor;
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.core.IsNot.not;

@RunWith(AndroidJUnit4.class)
@LargeTest
/**
*Scan test to test the full flow of document scan from Scanning to Save page.
*/
public class ScanActivityTest extends AbstractIT {

@Rule public ActivityScenarioRule<ScanActivity> activityRule = new ActivityScenarioRule<>(ScanActivity.class);

@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.CAMERA);

private int docScanCount = 0;

@Test
/**
* running all test in one test will create a flow from scanning to saving the scans
*/
public void runAllScanTests() {
verifyIfToolbarHidden();
verifyIfScanFragmentReplaced();
verifyToggleAutomatic();
verifyToggleFlash();
captureAndVerifyDocScan();
verifyScanMoreDocument();
verifyApplyFilter();
verifyRotateDocument();
verifyImageCrop();
verifyImageDeletion();
verifySaveScannedDocs();
verifyPasswordSwitch();
verifyPdfPasswordSwitchToggle();
}

public void verifyIfToolbarHidden() {
onView(withId(R.id.toolbar)).check(matches(not(isDisplayed())));
}


public void verifyIfScanFragmentReplaced() {
onView(withId(R.id.scan_doc_btn_automatic)).check(matches(isDisplayed()));
onView(withId(R.id.scan_doc_btn_flash)).check(matches(isDisplayed()));
onView(withId(R.id.scan_doc_btn_cancel)).check(matches(isDisplayed()));
onView(withId(R.id.shutterButton)).check(matches(isDisplayed()));
}


public void verifyToggleAutomatic() {
onView(withId(R.id.scan_doc_btn_automatic)).perform(click());
onView(withId(R.id.scan_doc_btn_automatic)).check(matches(hasTextColor(R.color.grey_60)));

onView(withId(R.id.scan_doc_btn_automatic)).perform(click());
onView(withId(R.id.scan_doc_btn_automatic)).check(matches(hasTextColor(R.color.primary)));
}


public void verifyToggleFlash() {
onView(withId(R.id.scan_doc_btn_flash)).perform(click());
onView(withId(R.id.scan_doc_btn_flash)).check(matches(hasTextColor(R.color.primary)));

onView(withId(R.id.scan_doc_btn_flash)).perform(click());
onView(withId(R.id.scan_doc_btn_flash)).check(matches(hasTextColor(R.color.grey_60)));
}


public void captureAndVerifyDocScan() {
onView(withId(R.id.shutterButton)).perform(click());
shortSleep();
shortSleep();
shortSleep();
docScanCount++;
assertEquals(docScanCount, ScanActivity.originalScannedImages.size());
}

public void verifyScanMoreDocument() {
onView(withId(R.id.scanMoreButton)).perform(click());
captureAndVerifyDocScan();
}

public void verifyApplyFilter() {
onView(withId(R.id.filterDocButton)).perform(click());

onView(withText(R.string.edit_scan_filter_dialog_title))
.inRoot(isDialog())
.check(matches(isDisplayed()));

onView(withText(R.string.edit_scan_filter_b_n_w))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());

shortSleep();
shortSleep();
shortSleep();
}


public void verifyRotateDocument() {
onView(withId(R.id.rotateDocButton)).perform(click());
}


public void verifyImageCrop() {
onView(withId(R.id.cropDocButton)).perform(click());

onView(withId(R.id.crop_polygon_view)).check(matches(isDisplayed()));
onView(withId(R.id.crop_btn_reset_borders)).check(matches(isDisplayed()));

onView(withId(R.id.action_save)).perform(click());
}


public void verifyImageDeletion() {
onView(withId(R.id.deleteDocButton)).perform(click());
docScanCount--;
assertEquals(docScanCount, ScanActivity.originalScannedImages.size());
}


public void verifySaveScannedDocs() {
onView(withId(R.id.action_save)).perform(click());

onView(withId(R.id.scan_save_filename_input)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_location_input)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_nested_scroll_view)).perform(swipeUp());

onView(withId(R.id.scan_save_without_txt_recognition_pdf_checkbox)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_without_txt_recognition_png_checkbox)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_without_txt_recognition_jpg_checkbox)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_with_txt_recognition_pdf_checkbox)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_with_txt_recognition_txt_checkbox)).check(matches(isDisplayed()));

onView(withId(R.id.scan_save_without_txt_recognition_pdf_checkbox)).check(matches(not(isChecked())));
onView(withId(R.id.scan_save_without_txt_recognition_png_checkbox)).check(matches(not(isChecked())));
onView(withId(R.id.scan_save_without_txt_recognition_jpg_checkbox)).check(matches(not(isChecked())));
onView(withId(R.id.scan_save_with_txt_recognition_pdf_checkbox)).check(matches(isChecked()));
onView(withId(R.id.scan_save_with_txt_recognition_txt_checkbox)).check(matches(not(isChecked())));

onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(isDisplayed()));
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(isEnabled()));
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(not(isChecked())));
onView(withId(R.id.scan_save_pdf_password_text_input)).check(matches(not(isDisplayed())));

onView(withId(R.id.save_scan_btn_cancel)).check(matches(isDisplayed()));
onView(withId(R.id.save_scan_btn_save)).check(matches(isDisplayed()));
}


public void verifyPasswordSwitch() {
onView(withId(R.id.scan_save_with_txt_recognition_pdf_checkbox)).perform(click());
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(not(isEnabled())));
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(not(isChecked())));

onView(withId(R.id.scan_save_without_txt_recognition_pdf_checkbox)).perform(click());
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(isEnabled()));
onView(withId(R.id.scan_save_pdf_password_switch)).check(matches(not(isChecked())));

}


public void verifyPdfPasswordSwitchToggle() {
onView(withId(R.id.scan_save_pdf_password_switch)).perform(click());
onView(withId(R.id.scan_save_pdf_password_text_input)).check(matches(isDisplayed()));

onView(withId(R.id.scan_save_pdf_password_switch)).perform(click());
onView(withId(R.id.scan_save_pdf_password_text_input)).check(matches(not(isDisplayed())));
}

}
Loading