Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.ListView;
import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -198,9 +199,13 @@ public void testSendMessageAndReceiveResponse() throws Exception {
// Click send button
onView(withId(R.id.sendButton)).perform(click());

// --- Wait for response and validate ---
// Wait 50 seconds for model to generate response
Thread.sleep(50000);
// --- Wait for generation to complete ---
// Give a brief moment for generation to start (button becomes non-clickable)
Thread.sleep(500);

// Wait for generation to complete (button becomes clickable again)
boolean generationComplete = waitForButtonState(scenario, true, 120000); // 2 minute timeout
assertTrue("Generation should complete", generationComplete);

// Extract all messages from the list
AtomicInteger messageCount = new AtomicInteger(0);
Expand Down Expand Up @@ -265,6 +270,32 @@ private boolean waitForModelLoaded(ActivityScenario<MainActivity> scenario, long
return false;
}

/**
* Waits for the send button to reach the expected clickable state.
*
* @param scenario the activity scenario
* @param expectedClickable the expected clickable state (true = clickable/send, false = non-clickable/stop)
* @param timeoutMs maximum time to wait in milliseconds
* @return true if button reached expected state, false if timeout
*/
private boolean waitForButtonState(ActivityScenario<MainActivity> scenario, boolean expectedClickable, long timeoutMs) throws InterruptedException {
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < timeoutMs) {
AtomicReference<Boolean> isClickable = new AtomicReference<>(null);
scenario.onActivity(activity -> {
ImageButton sendButton = activity.findViewById(R.id.sendButton);
if (sendButton != null) {
isClickable.set(sendButton.isClickable());
}
});
if (isClickable.get() != null && isClickable.get() == expectedClickable) {
return true;
}
Thread.sleep(200); // Poll every 200ms
}
return false;
}

/**
* Writes the model response to logcat with a special tag for extraction.
* The response can be extracted from logcat using: grep "LLAMA_RESPONSE"
Expand Down