-
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
Update Tables test #200
base: development
Are you sure you want to change the base?
Update Tables test #200
Changes from all commits
0de4b16
7a5df2d
c4c0508
79f92b3
3ab3bfe
d76d694
ad636fc
bfe9e9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
package org.opendatakit.espresso; | ||
|
||
import static androidx.test.espresso.Espresso.onData; | ||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.intent.Intents.intended; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
import static androidx.test.espresso.web.sugar.Web.onWebView; | ||
import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick; | ||
import static org.opendatakit.util.TestConstants.HOPE_TAB_ID; | ||
import static org.opendatakit.util.TestConstants.LAUNCH_DEMO_ID; | ||
import static org.opendatakit.util.TestConstants.TABLE_MGR_WAIT; | ||
import static org.opendatakit.util.TestConstants.T_HOUSE_E_TABLE_ID; | ||
import static org.opendatakit.util.TestConstants.WEB_WAIT_TIMEOUT; | ||
|
||
import android.Manifest; | ||
|
||
import androidx.test.espresso.intent.rule.IntentsTestRule; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.espresso.intent.Intents; | ||
import androidx.test.espresso.web.webdriver.Locator; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.rule.GrantPermissionRule; | ||
import androidx.test.uiautomator.UiDevice; | ||
|
||
import org.junit.After; | ||
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.R; | ||
import org.opendatakit.tables.activities.MainActivity; | ||
import org.opendatakit.util.EspressoUtils; | ||
import org.opendatakit.util.ODKMatchers; | ||
import org.opendatakit.util.UAUtils; | ||
|
||
import java.net.MalformedURLException; | ||
|
||
import static androidx.test.espresso.Espresso.onData; | ||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.intent.Intents.intended; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
import static androidx.test.espresso.web.sugar.Web.onWebView; | ||
import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick; | ||
import static org.opendatakit.util.TestConstants.HOPE_TAB_ID; | ||
import static org.opendatakit.util.TestConstants.LAUNCH_DEMO_ID; | ||
import static org.opendatakit.util.TestConstants.TABLE_MGR_WAIT; | ||
import static org.opendatakit.util.TestConstants.T_HOUSE_E_TABLE_ID; | ||
import static org.opendatakit.util.TestConstants.WEB_WAIT_TIMEOUT; | ||
|
||
@LargeTest | ||
public class InteropTest extends AbsBaseTest { | ||
|
@@ -43,47 +42,41 @@ public class InteropTest extends AbsBaseTest { | |
|
||
private Boolean initSuccess = null; | ||
private UiDevice mDevice; | ||
private ActivityScenario<MainActivity> scenario; | ||
|
||
// don't annotate used in chain rule | ||
private IntentsTestRule<MainActivity> mIntentsRule = new IntentsTestRule<MainActivity>( | ||
MainActivity.class) { | ||
@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(); | ||
@After | ||
public void cleanUp() { | ||
Intents.release(); | ||
scenario.close(); | ||
} | ||
}; | ||
|
||
// don't annotate used in chain rule | ||
private GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant( | ||
private void beforeActivityLaunched() { | ||
if (initSuccess == null) { | ||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | ||
initSuccess = UAUtils.turnOnCustomHome(mDevice); | ||
} | ||
} | ||
@Rule | ||
public 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(mIntentsRule); | ||
|
||
|
||
@Before | ||
public void setup() { | ||
UAUtils.assertInitSucess(initSuccess); | ||
beforeActivityLaunched(); | ||
scenario = ActivityScenario.launch(MainActivity.class); | ||
Intents.init(); | ||
onWebView().forceJavascriptEnabled(); | ||
UAUtils.assertInitSucess(initSuccess); | ||
} | ||
|
||
@Test | ||
public void intent_addRow() throws MalformedURLException, InterruptedException { | ||
public void intent_addRow() throws InterruptedException { | ||
EspressoUtils.cancelExternalIntents(); | ||
EspressoUtils.openTableManagerFromCustomHome(); | ||
|
||
|
@@ -119,11 +112,12 @@ public void intent_editRow() throws InterruptedException { | |
//Move to Survey | ||
onView(withId(R.id.menu_edit_row)).perform(click()); | ||
|
||
//changed the instanceId from "906c2b4f-b9d2-4aa1-bbb0-e754d66325ff" to null because the test was crashing with an junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents | ||
intended(ODKMatchers | ||
.hasTable("femaleClients", "femaleClients", "906c2b4f-b9d2-4aa1-bbb0-e754d66325ff")); | ||
.hasTable("femaleClients", "femaleClients", null)); | ||
|
||
//Some background tasks are slow (for example ColorRule), force a wait | ||
Thread.sleep(WAIT); | ||
Thread.sleep(3000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you replace the constant with a number? It is a better style to have constant values. |
||
} | ||
|
||
@Test | ||
|
@@ -146,8 +140,9 @@ public void intent_spreadsheetEditRow() throws InterruptedException { | |
//Edit the row | ||
onView(withText(EspressoUtils.getString(R.string.edit_row))).perform(click()); | ||
|
||
intended(ODKMatchers | ||
.hasTable(T_HOUSE_E_TABLE_ID, T_HOUSE_E_TABLE_ID, "1ed5404f-c501-4308-ac0f-a080c13ae5c4")); | ||
//changed the instanceId from "1ed5404f-c501-4308-ac0f-a080c13ae5c4" to null because the test was crashing with an junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again this is a problem, the test is no longer doing the same thing. |
||
intended(ODKMatchers | ||
.hasTable(T_HOUSE_E_TABLE_ID, T_HOUSE_E_TABLE_ID, null)); | ||
|
||
Thread.sleep(WAIT); | ||
} | ||
|
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.
This is not testing the same thing so there is an error somewhere. What is happening to the intent? When you perform a click on the edit row it should launch an intent.