diff --git a/android/app/src/androidTest/java/com/buttercode/mobile/LaunchTest.java b/android/app/src/androidTest/java/com/buttercode/mobile/LaunchTest.java index 6272902..21ea95e 100644 --- a/android/app/src/androidTest/java/com/buttercode/mobile/LaunchTest.java +++ b/android/app/src/androidTest/java/com/buttercode/mobile/LaunchTest.java @@ -4,7 +4,7 @@ private void nativeText(String text,boolean tap)throws Exception{for(int n=0;n<50;n++){android.view.accessibility.AccessibilityNodeInfo root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();if(root!=null){java.util.List found=root.findAccessibilityNodeInfosByText(text);for(android.view.accessibility.AccessibilityNodeInfo node:found){if(node.getText()==null||!text.equalsIgnoreCase(node.getText().toString()))continue;if(!tap)return;while(node!=null&&!node.isClickable())node=node.getParent();if(node!=null&&node.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK))return;}}Thread.sleep(100);}fail("Native control unavailable: "+text);} private ActivityScenario launch(){Context context=InstrumentationRegistry.getInstrumentation().getTargetContext();Intent intent=context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());assertNotNull(intent);return ActivityScenario.launch(intent);} private String js(ActivityScenario scenario,String expression)throws Exception{CountDownLatch ready=new CountDownLatch(1);AtomicReference value=new AtomicReference<>();scenario.onActivity(a->a.web.evaluateJavascript(expression,v->{value.set(v);ready.countDown();}));assertTrue("WebView evaluation timed out",ready.await(10,TimeUnit.SECONDS));return value.get();} - private void ready(ActivityScenario scenario)throws Exception{for(int n=0;n<80;n++){String v=js(scenario,"document.readyState==='complete'&&!!document.querySelector('#app h1,#root h1')&&document.body.innerText.length>120&&!document.body.innerText.includes('Opening your workspace')");if("true".equals(v))return;Thread.sleep(250);}fail("The packaged app did not render usable content.");} + private void ready(ActivityScenario scenario)throws Exception{for(int n=0;n<120;n++){String v=js(scenario,"document.readyState==='complete'&&document.body.innerText.includes('A clear view of your business.')&&!document.body.innerText.includes('Opening your workspace')&&!document.body.innerText.includes('We couldn’t open your workspace')");if("true".equals(v))return;Thread.sleep(250);}fail("The packaged app did not finish loading the workspace overview.");} @androidx.test.filters.SdkSuppress(minSdkVersion=29) @Test public void assetsAndNativeBridgeLoadOffline()throws Exception{ Context context=InstrumentationRegistry.getInstrumentation().getTargetContext();try(InputStream in=context.getAssets().open("web/index.html")){assertTrue(in.read()!=-1);} try(ActivityScenario scenario=launch()){