Keyevent doesn't work - android

I have a problem with keyevents when I try to press the home button.
Where is the bug?
driver.execute_script("mobile: keyevent", {"keycode": 3})
I use python and appium.

The solution to the problem were extra spaces.
The code should look like this:
driver.execute_script("mobile: keyevent",{ "keycode": 3 })

Related

How to perform actionDone event of EditText with Espresso

Question in the title.
I tried something like:
onView(withId(R.id.search_edit_text))
.perform(typeText("some"), pressKey(KeyEvent.KEYCODE_ENTER));
But it doesn't work. Keyboard is still shown and TextView.OnEditorActionListener not called. Any ideas?
Try
onView(withId(R.id.search_edit_text))
.perform(typeText("some"), pressImeActionButton());
I used KEYCODE_BACK and it works well. KEYCODE_ENTER not working on my device SAMSUNG A70
onView(withId(R.id.edit_text).perform(ViewActions.pressKey(KeyEvent.KEYCODE_BACK))

Closing Bootstrap modals in android with phonegap

I am using this bootstrap modals (popups) and they work great in my browser. The problem is, when I launch them on android using phonegap, they do not close when the close button is pressed. When I click on the ovelay next to the popup, everything seems to be working alright ;/ I am very confised...
EDIT: I use exactly the same code as in the example and something goes wrong...
I added this function to my angular.js controller:
$scope.closeModal = function (idOfModal) {
$(idOfModal).modal('hide');
}
And also to the confirm/save buttons of modals, after the controller's function is executed, at the very end again I add $(idOfModal).modal('hide');, where I also pass idOfModal to the function ;)

Espresso - typeText not working

I'm trying to type some text inside an EditText:
public void testSearch() {
onView(withId(R.id.titleInput)).perform(typeText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
I see the EditText is getting focus, but nothing happens. No text is typed.
I tried this on a phone and an emulator - same result.
Looks like I figured out the issue. It had to do with hardware vs software keyboard.
For Emulators:
Go to Settings -> Language & Input -> switch the Default Input to Sample Soft Keyboard.
For Phones:
Install a software keyboard from the Play store and switch to it. It appears that the native keyboards of some phones do not work.
It works now.
Had the same issue using Espresso 2. As a workaround I'm using replaceText instead of typeText.
public void testSearch() {
onView(withId(R.id.titleInput)).perform(click(), replaceText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
If the EditText does not has the focus yet, you should click on it first. If this solves your problem, then there is no bug.
onView(withId(R.id.titleInput)).perform(click()).perform(typeText("Engineer"));
You can bypass the problem by calling setText on the EditText.
final EditText titleInput = (EditText) activity.findViewById(R.id.titleInput);
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
titleInput.setText("Engineer");
}
});
Same issue resolved with the following:
editText.perform(scrollTo(), click(), clearText(), typeText(myInput), closeSoftKeyboard())
Interestingly, I only ever had a problem when my machine was working hard.
You can include it with in the code like this,
onView(withId(R.id.titleInput))
.perform(click(), replaceText("Engineer"), closeSoftKeyboard());
I fixed this issue by setting layout_height="wrap_content" on the View I wanted to click(). Maybe it can help someone here.
If you're using Genymotion, you may need to switch the default keyboard in Genymotion Configuration (it's an app on the emulator).
Go to Apps -> Genymotion Configuration -> Keyboard -> Virtual keyboard (click "Yes" when you're prompted to reboot)
NOTE: These changes do not persist after you close the emulator. You will need to set this every time you start the emulator.
for me I was annotated my test method with #UiThreadTest. I removed that and it solved.
Adding closeSoftKeyboard() after typeText() worked for me.
CODE:
onView(withId(R.id.editTextUserInput))
.perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
This is how it is documented in the Android docs.

how to use Enter on softkeyboard for my app?

I have big problem with my keyevent i am trying to call my another acvitity but the keyevent is not working please check what mistake i made for my code. actually i created one carousel design if i press softkeyboard enter button in my laptop the keyevent is not working...
This case is not working for me...
case KeyEvent.KEYCODE_ENTER:
System.out.println("enter pressed");
if(position==0);{
Intent intent = new Intent(sampleActivity.this, test.class);
startActivity(intent);
}
I suppose you need to enable your keyboard input. Even though the developer documentation says keyboard support is enabled by default it doesn't seem to be that way in SDK rev 20. I explicitly enabled keyboard support in my emulator's config.ini file and that worked!
Add: hw.keyboard=yes
To: ~/.android/avd/.avd/config.ini
Reference: http://developer.android.com/tools/devices/managing-avds-cmdline.html#hardwareopts
Your code seems correct (apart from the synthax error), the only difference I see from working examples is your event.getAction() condition. I'd suggest to check the ACTION_DOWN clause.

How to implement the event onkeyup in JQuery witout using JQuery mobile?

I have a mobile app and I can't use JQuery Mobile at the moment, only JQuery.
I found out that in Android mobile the "onkeyup" event is not working at all, only if the user type "back" the event fires.
I have one "input" field (HTML5) and need to attach the onkeyup event to it. What to do? I tried to replace the val(), adding the val somhting like "#" and remove it quickly. It doesn't helped.
Any ideas?
You can use this below.
$(document).ready(function() {
$("#MyElement").keyup(Function(e) {
$("#MyElement").val("MyValue");
});
});
the e param should tell you what key was pressed with the properties keycode and which.
hope this lends you to the right direction.

Categories

Resources