Skip to content

Commit

Permalink
🔀 Merge pull request #7 from FleksySDK/change_starting_method_for_typ…
Browse files Browse the repository at this point in the history
…ing_field

Change typing field for Android
  • Loading branch information
astariul authored Mar 29, 2024
2 parents b4c85c8 + ff4d525 commit 66bda6c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
Binary file removed docs/assets/emu_setup_3.webp
Binary file not shown.
Binary file removed docs/assets/emu_setup_4.webp
Binary file not shown.
24 changes: 3 additions & 21 deletions docs/emu_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,10 @@ adb devices
export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH
```

### Preparing the emulator
!!! info
In Android, to open the keyboard, we access a notepad website ([www.justnotepad.com](www.justnotepad.com)).

When we run the tests on emulator, we need to access a typing field, and type the words there while monitoring the suggestions and the corrected words.

But not all typing fields are equal ! Some typing fields (like URL field, or search field) have AC disabled by default.

On Android, we access the Google Message app, and compose a new message (in this field, the AC is enabled by default).

But the first time you access the app on Android, a pop-up appears, requiring user intervention. If you try to run the tests without closing this pop-pup, the layout detection will fails and the testing function will fail.

So, before running any tests on a freshly installed emulator, open the Google Message app manually :

![](assets/emu_setup_3.webp){ width="250" }

And when the pop-up appears, discard it so it doesn't appear again :

![](assets/emu_setup_4.webp){ width="300" }

!!! info "Note"
Depending on your version of the Google Message app, the pop-up might be different.

Or there might be several pop-ups to close, when you open the app for the second or third time. Just make sure to close them all until they don't appear anymore upon starting the app.
The reason we do that is because it's the easiest way to access a typing field, and it works across versions and emulators.

### Preparing GBoard

Expand Down
24 changes: 11 additions & 13 deletions kebbie/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webelement import WebElement


Expand Down Expand Up @@ -52,11 +51,8 @@
}
DEFAULT_IOS_NAME = "iPhone 15 Pro"
DEFAULT_IOS_PLATFORM = "17.4"
APP_PACKAGE = "com.google.android.apps.messaging"
APP_ACTIVITY = "com.google.android.apps.messaging.ui.ConversationListActivity"
ANDROID_TYPING_FIELD_ID = "com.google.android.apps.messaging:id/compose_message_text"
ANDROID_START_CHAT_FIELD_ID = "com.google.android.apps.messaging:id/start_chat_fab"
ANDROID_RECIPIENT_FIELD_ID = "com.google.android.apps.messaging:id/recipient_text_view"
BROWSER_PAD_URL = "https://www.justnotepad.com"
ANDROID_TYPING_FIELD_CLASS_NAME = "android.widget.EditText"
DUMMY_RECIPIENT = "0"
IOS_TYPING_FIELD_ID = "messageBodyField"
IOS_START_CHAT_CLASS_NAME = "XCUIElementTypeCell"
Expand Down Expand Up @@ -295,13 +291,15 @@ def _access_typing_field(self):
will type our text.
"""
if self.platform == ANDROID:
self.driver.start_activity(APP_PACKAGE, APP_ACTIVITY)
self.driver.find_element(By.ID, ANDROID_START_CHAT_FIELD_ID).click()
recipient = self.driver.find_element(By.ID, ANDROID_RECIPIENT_FIELD_ID)
recipient.click()
recipient.send_keys(DUMMY_RECIPIENT)
ActionChains(self.driver).send_keys(Keys.RETURN).perform()
self.typing_field = self.driver.find_element(By.ID, ANDROID_TYPING_FIELD_ID)
subprocess.run(
["adb", "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", BROWSER_PAD_URL],
stdout=subprocess.PIPE,
)
typing_field_loaded = False
while not typing_field_loaded:
typing_fields = self.driver.find_elements(By.CLASS_NAME, ANDROID_TYPING_FIELD_CLASS_NAME)
typing_field_loaded = len(typing_fields) == 2
self.typing_field = typing_fields[0]
else:
self.driver.find_element(By.CLASS_NAME, IOS_START_CHAT_CLASS_NAME).click()
self.typing_field = self.driver.find_element(By.ID, IOS_TYPING_FIELD_ID)
Expand Down

0 comments on commit 66bda6c

Please sign in to comment.