-
Notifications
You must be signed in to change notification settings - Fork 94
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
add UI test for select tag in webview #179
Open
starboi02
wants to merge
2
commits into
odk-x:development
Choose a base branch
from
starboi02:add-test
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
tables_app/src/androidTestUitest/java/org/opendatakit/espresso/HTMLSelectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.opendatakit.espresso; | ||
|
||
import android.Manifest; | ||
import android.webkit.WebView; | ||
|
||
import androidx.test.espresso.Espresso; | ||
import androidx.test.espresso.web.model.Atom; | ||
import androidx.test.espresso.web.model.ElementReference; | ||
import androidx.test.espresso.web.webdriver.Locator; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.rule.GrantPermissionRule; | ||
import androidx.test.uiautomator.UiDevice; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TestRule; | ||
import org.opendatakit.tables.activities.MainActivity; | ||
import org.opendatakit.util.UAUtils; | ||
|
||
import static androidx.test.espresso.web.sugar.Web.onWebView; | ||
import static androidx.test.espresso.web.webdriver.DriverAtoms.findElement; | ||
import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick; | ||
|
||
/** | ||
* Basic sample that shows the usage of Espresso web showcasing API. | ||
* <p/> | ||
* The sample has a simple layout which contains a single {@link WebView}. The HTML page displays | ||
* a form with an input tag and buttons to submit the form. | ||
*/ | ||
@LargeTest | ||
public class HTMLSelectTest { | ||
|
||
private Boolean initSuccess = null; | ||
private UiDevice mDevice; | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<MainActivity>( | ||
MainActivity.class, false, true) { | ||
@Override | ||
protected void beforeActivityLaunched() { | ||
super.beforeActivityLaunched(); | ||
|
||
if (initSuccess == null) { | ||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | ||
initSuccess = UAUtils.turnOnCustomHome(mDevice); | ||
} | ||
} | ||
|
||
@Override | ||
protected void afterActivityLaunched() { | ||
super.afterActivityLaunched(); | ||
|
||
onWebView().forceJavascriptEnabled(); | ||
} | ||
}; | ||
|
||
// don't annotate used in chain rule | ||
private GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant( | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.READ_EXTERNAL_STORAGE, | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
); | ||
|
||
@Rule | ||
public TestRule chainedRules = RuleChain | ||
.outerRule(grantPermissionRule) | ||
.around(mActivityRule); | ||
|
||
@Before | ||
public void setup() { | ||
UAUtils.assertInitSucess(initSuccess); | ||
} | ||
|
||
@Test | ||
public void infiniteTestToReplicateSigabrt() { | ||
if (true) | ||
return; | ||
|
||
// Run through the Tables app an infinite number of times to get a | ||
// crash | ||
int numOfTimesToRun = 400; | ||
int numOfMsToSleep = 0; | ||
for (int i = 0; i < numOfTimesToRun; i++) { | ||
boolean found = false; | ||
Atom<ElementReference> elementFound = findElement(DriverAtoms.findElement(Locator.SELECT, "select")); | ||
while (!found) { | ||
found = true; | ||
try { | ||
Thread.sleep(numOfMsToSleep); | ||
onWebView() | ||
// Find the input element by ID | ||
.withElement(DriverAtoms.findElement(Locator.TAG_NAME, "select")) | ||
// Launch into teahouses | ||
.perform(webClick()); | ||
} catch (RuntimeException e) { | ||
//e.printStackTrace(); | ||
System.out.println("Failed to find the select tag"); | ||
found = false; | ||
} catch (InterruptedException ie) { | ||
System.out.println("Error with thread sleep"); | ||
} | ||
} | ||
|
||
Espresso.pressBack(); | ||
|
||
System.out.println("Number of iterations = " + i); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first findElement uses your static import the second one is missing an import statement so it won't compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also Locator.SELECT is not resolving
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have resolved the errors and compiled it against build variant snapshotUiTestDebug