From d782422e4d41d1b4e1703a870602f7a2dc2102c2 Mon Sep 17 00:00:00 2001 From: Quentin Monnier Date: Mon, 23 Jan 2023 19:50:46 -0600 Subject: [PATCH] bug fix --- app/build.gradle | 7 ++----- .../linphone/call/IncomingCallPushUITests.kt | 17 +++++------------ .../org/linphone/call/IncomingCallUITests.kt | 14 ++++++++++---- .../org/linphone/call/OutgoingCallUITests.kt | 1 + .../linphone/methods/CallViewUITestsMethods.kt | 9 +++------ .../org/linphone/methods/UITestsCoreManager.kt | 1 - .../java/org/linphone/methods/UITestsUtils.kt | 4 +++- 7 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 18144b64b..cc8d5b1d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -88,10 +88,8 @@ android { versionName "${project.version}" applicationId getPackageName() - //testInstrumentationRunnerArguments clearPackageData: 'true' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testOptions { - //execution 'ANDROIDX_TEST_ORCHESTRATOR' animationsDisabled = true } } @@ -264,10 +262,9 @@ dependencies { debugImplementation 'androidx.test:core:1.5.0' debugImplementation 'androidx.test.ext:junit-ktx:1.1.4' - debugImplementation 'androidx.test.espresso:espresso-core:3.5.0' - debugImplementation 'androidx.test.espresso:espresso-idling-resource:3.5.0' + debugImplementation 'androidx.test.espresso:espresso-core:3.4.0' + debugImplementation 'androidx.test.espresso:espresso-idling-resource:3.4.0' debugImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' - //androidTestUtil 'androidx.test:orchestrator:1.4.2' } task generateContactsXml(type: Copy) { diff --git a/app/src/androidTest/java/org/linphone/call/IncomingCallPushUITests.kt b/app/src/androidTest/java/org/linphone/call/IncomingCallPushUITests.kt index 101308de7..752d49a58 100644 --- a/app/src/androidTest/java/org/linphone/call/IncomingCallPushUITests.kt +++ b/app/src/androidTest/java/org/linphone/call/IncomingCallPushUITests.kt @@ -1,11 +1,8 @@ package org.linphone.call -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.rule.GrantPermissionRule -import java.util.* import org.junit.After import org.junit.Before import org.junit.Rule @@ -43,39 +40,35 @@ class IncomingCallPushUITests { } @Test - fun testDisplayCallPush() { + fun testPushDisplay() { methods.endCall() takeScreenshot("dialer_view") } @Test - fun testNoAnswerCallPush() { + fun testNoAnswer() { methods.waitForCallNotification(false, 30.0) takeScreenshot("dialer_view") } @Test - fun testClickOnCallPush() { - val time = Date().time + fun testOnClick() { methods.onPushAction(getString(R.string.incoming_call_notification_title), UITestsView.incomingCallView) - methods.checkCallTime(onView(withId(R.id.incoming_call_timer)), time) takeScreenshot("incoming_call_view") methods.endCall(UITestsView.incomingCallView) takeScreenshot("dialer_view") } @Test - fun testDeclineCallPush() { + fun testDecline() { methods.onPushAction("Decline", null) methods.waitForCallNotification(false, 5.0) takeScreenshot("dialer_view") } @Test - fun testAnswerCallPush() { - val time = Date().time + fun testAnswer() { methods.onPushAction(getString(R.string.incoming_call_notification_answer_action_label), UITestsView.singleCallView) - methods.checkCallTime(onView(withId(R.id.active_call_timer)), time) takeScreenshot("single_call_view") methods.endCall(UITestsView.singleCallView) takeScreenshot("dialer_view") diff --git a/app/src/androidTest/java/org/linphone/call/IncomingCallUITests.kt b/app/src/androidTest/java/org/linphone/call/IncomingCallUITests.kt index cec5a7a56..3ca9ebcf4 100644 --- a/app/src/androidTest/java/org/linphone/call/IncomingCallUITests.kt +++ b/app/src/androidTest/java/org/linphone/call/IncomingCallUITests.kt @@ -1,11 +1,14 @@ package org.linphone.call +import androidx.test.espresso.Espresso.onView import androidx.test.espresso.assertion.ViewAssertions.doesNotExist import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.rule.GrantPermissionRule +import java.util.* import org.junit.After import org.junit.Before import org.junit.Rule @@ -22,6 +25,7 @@ import org.linphone.utils.AppUtils.Companion.getString class IncomingCallUITests { val methods = CallViewUITestsMethods + var time = Date().time // to pass time value between setup and test function for call timer check @get:Rule val screenshotsRule = ScreenshotsRule(true) @@ -35,6 +39,7 @@ class IncomingCallUITests { methods.refreshAccountInfo() takeScreenshot("dialer_view") methods.startIncomingCall() + time = Date().time methods.onPushAction(getString(R.string.incoming_call_notification_title), UITestsView.incomingCallView) takeScreenshot("incoming_call_view") } @@ -45,25 +50,26 @@ class IncomingCallUITests { } @Test - fun testOpenIncomingCallView() { + fun testViewDisplay() { + methods.checkCallTime(onView(ViewMatchers.withId(R.id.outgoing_call_timer)), time) methods.endCall(UITestsView.incomingCallView) takeScreenshot("dialer_view") } @Test - fun testNoAnswerIncomingCallView() { + fun testNoAnswer() { UITestsView.incomingCallView.checkWithTimeout(doesNotExist(), 30.0) takeScreenshot("dialer_view") } @Test - fun testDeclineIncomingCallView() { + fun testDecline() { methods.onCallAction(R.id.hangup, UITestsView.incomingCallView, doesNotExist()) takeScreenshot("dialer_view") } @Test - fun testAcceptIncomingCallView() { + fun testAccept() { methods.onCallAction(R.id.answer, UITestsView.singleCallView, matches(isDisplayed())) takeScreenshot("single_call_view") methods.endCall(UITestsView.singleCallView) diff --git a/app/src/androidTest/java/org/linphone/call/OutgoingCallUITests.kt b/app/src/androidTest/java/org/linphone/call/OutgoingCallUITests.kt index cdc021414..878672989 100644 --- a/app/src/androidTest/java/org/linphone/call/OutgoingCallUITests.kt +++ b/app/src/androidTest/java/org/linphone/call/OutgoingCallUITests.kt @@ -45,6 +45,7 @@ class OutgoingCallUITests { @Test fun testViewDisplay() { + methods.checkCallTime(onView(withId(R.id.outgoing_call_timer))) methods.endCall(UITestsView.outgoingCallView) takeScreenshot("dialer_view", "declined") } diff --git a/app/src/androidTest/java/org/linphone/methods/CallViewUITestsMethods.kt b/app/src/androidTest/java/org/linphone/methods/CallViewUITestsMethods.kt index 4f853238f..724eda82a 100644 --- a/app/src/androidTest/java/org/linphone/methods/CallViewUITestsMethods.kt +++ b/app/src/androidTest/java/org/linphone/methods/CallViewUITestsMethods.kt @@ -30,8 +30,6 @@ object CallViewUITestsMethods { var appAccountAuthInfo: AuthInfo = UITestsCoreManager.instance.appAccountAuthInfo var ghostAccount: UITestsRegisteredLinphoneCore = UITestsCoreManager.instance.ghostAccounts[0] - var callTimeChecker: Job? = null - fun refreshAccountInfo() { appAccountAuthInfo = UITestsCoreManager.instance.appAccountAuthInfo ghostAccount = UITestsCoreManager.instance.ghostAccounts[0] @@ -52,12 +50,10 @@ object CallViewUITestsMethods { onView(withId(R.id.sip_uri_input)).perform(typeText(ghostAccount.mAuthInfo.username)) onView(withContentDescription(R.string.content_description_start_call)).perform(click()) - onView(withId(R.id.outgoing_call_layout)).checkWithTimeout(matches(isDisplayed()), 5.0) - callTimeChecker = checkCallTime(onView(withId(R.id.outgoing_call_timer))) + UITestsView.outgoingCallView.checkWithTimeout(matches(isDisplayed()), 5.0) } fun endCall(currentView: ViewInteraction? = null) { - runBlocking { callTimeChecker?.join() } if (ghostAccount.callState == Call.State.Released) { return } ghostAccount.terminateCall() @@ -69,7 +65,7 @@ object CallViewUITestsMethods { fun checkCallTime(view: ViewInteraction, launchTime: Long = Date().time) = runBlocking { view.checkWithTimeout(matches(isDisplayed()), 2.0) val firstValue = ((Date().time - launchTime) / 1000).toInt() + 1 - launch(Dispatchers.Default) { + val wait = launch(Dispatchers.Default) { val timerArray = arrayListOf() repeat(3) { view.check { view, _ -> @@ -82,6 +78,7 @@ object CallViewUITestsMethods { assert(timerArray == timerArray.sorted()) { "[UITests] Call Time is not correctly incremented, it is not increasing" } assert(timerArray.first() <= firstValue + 3) { "[UITests] Call Time is not correctly initialized, it is at ${timerArray.first()}, $firstValue seconds after the start)" } } + wait.join() } fun onPushAction(label: String, resultingView: ViewInteraction?, timeout: Double = 5.0) { diff --git a/app/src/androidTest/java/org/linphone/methods/UITestsCoreManager.kt b/app/src/androidTest/java/org/linphone/methods/UITestsCoreManager.kt index 070b78dab..d354ebff7 100644 --- a/app/src/androidTest/java/org/linphone/methods/UITestsCoreManager.kt +++ b/app/src/androidTest/java/org/linphone/methods/UITestsCoreManager.kt @@ -202,7 +202,6 @@ class UITestsRegisteredLinphoneCore(authInfo: AuthInfo) { mCore.addAccount(account) mAccount = account mCore.defaultAccount = mAccount - waitForRegistrationState(RegistrationState.Ok, 5.0) } fun startCall(address: Address) { diff --git a/app/src/androidTest/java/org/linphone/methods/UITestsUtils.kt b/app/src/androidTest/java/org/linphone/methods/UITestsUtils.kt index c50b3b461..b81b12ba2 100644 --- a/app/src/androidTest/java/org/linphone/methods/UITestsUtils.kt +++ b/app/src/androidTest/java/org/linphone/methods/UITestsUtils.kt @@ -152,8 +152,9 @@ object UITestsUtils { } fun ViewInteraction.checkWithTimeout(viewAssert: ViewAssertion, timeout: Double): ViewInteraction = runBlocking { + val time = Date().time val wait = launch(Dispatchers.Default) { - repeat(timeout.toInt() * 10) { + repeat((timeout * 10).toInt()) { try { check(viewAssert) cancel() @@ -164,6 +165,7 @@ object UITestsUtils { } } wait.join() + check { view, noViewFoundException -> Log.i("[UITests] $view (found in ${(Date().time - time).toFloat() / 1000} sec)") } check(viewAssert) } }