Unable to tap ‘search’ button on Android softKeyboard - android

I am trying to type in a search box within my app and tap/click on search button(magnifying glass) on keyboard. But I am unable to click/tap on it. I have tried below things:
driver.sendKeyEvent(84);
Appium says it successfully sent in the command but 'search' does not get tapped. Cursor remains in text box and results do not filter.
HashMap swipeObject = new HashMap();
swipeObject.put("keycode", 84);
((JavascriptExecutor ) driver).executeScript("mobile: keyevent", swipeObject);
Appium says not yet implemented.
JavascriptExecutor jse = (JavascriptExecutor) driver1; jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done'].tap();");
Appium says not yet implemented.
driver.sendKeyEvent(AndroidKeyCode.ENTER, AndroidKeyMetastate.META_FUNCTION_ON);
Appium says it successfully sent in the command but 'search' does not get tapped. Cursor remains in text box and results do not filter.
driver.sendKeyEvent(AndroidKeyCode.ENTER);
Nothing happens
All other send key events works except ENTER, Search. I can use sendKeyEvent for alphabets, numbers, space etc.
I am using Ecllipse, AndroidDriver, AppiumDriver, TestNG, Appium(1.2.4.1), Samsung Galaxy Note 3.
Any help on this would be really helpful. I went through lot of Googling but till not successful tapping search key.

Related

How to wait and grab the text of android.widget.TextView in an appium test when there is no resource_id?

The appium test is to perform certain combination of few input fields, and one field is password field.
If the username is already taken, a corresponding message will be shown below the password button saying "username already taken".
But if username is valid, but password is wrong, the message will be shown below as "username and password combo didn't work".
The error message in above cases is shown in a android.widget.TextView**
Two questions:
I recorded the test using Appium Studio. When I run the test, I want to wait for couple of second and grab the text of error message. How to do the wait part and grab the text? (More details below). THe challenge is there is no resource id for the textView, but xpath and other details are available.
Note: Since the error message is shown right below the pwd field, it has no resouceid, only xpath available.
This is the structure
<android.widget.LinearLayout resource-id="com.a.b/textinputlayout_lgin_username">
<android.widget.FrameLayout>
<android.widget.EditText resource-id="com.a.b/lgin_username_edit">
<!--above 3 lines are for username field, just added for more clarity -->
<android.widget.LinearLayout resource-id="com.a.b:id/textinputlayout_lgin_pwd">
<android.widget.FrameLayout>
<android.widget.EditText>
<android.widget.ImageButton resource-id="com.a.b/text_input_end_icon">
<android.widget.TextView> <!-- ** this is the text I'm trying to grab -->
<android.widget.TextView resource-id="com.a.b/tv_forgotpwd">
<android.widget.Button resource-id="com.a.b/btn_login">
Please help. Thanks.
I assume, you have no ability to update the app in order to add resource id for the element.
The best, you can do in this case, is to use xpath.
Find the first parent by resorce-id attribute, and then go down and search by tag. I see 2 text tag elements here in LinearLayout, so you might try to get the first text tag by index, or search for text tag without resouce id attribute.
"(//android.widget.LinearLayout[#resouce-id='com.a.b:id/textinputlayout_lgin_pwd']//android.widget.TextView)[1]"
or
"//android.widget.LinearLayout[#resouce-id='com.a.b:id/textinputlayout_lgin_pwd']//android.widget.TextView[not(#resouce-id)]"
Based on appium client you're using, just utilize webdriver wait + expected conditions and use xpath location strategy for the element.
PS: Here is the code
public class Test_9 {
private String reportDirectory = "reports";
private String reportFormat = "xml";
private String testName = "Untitled";
protected AndroidDriver<AndroidElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
#BeforeEach
public void setUp() throws MalformedURLException {
dc.setCapability("reportDirectory", reportDirectory);
dc.setCapability("reportFormat", reportFormat);
dc.setCapability("testName", testName);
dc.setCapability(MobileCapabilityType.UDID, "123456");
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.a.b");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.base.SplashActivity");
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
driver.setLogLevel(Level.INFO);
}
#Test
public void testUntitled() {
driver.findElement(By.xpath("(//*[#contentDescription='Google Map']/*[#class='android.view.View'])[26]")).click();
driver.findElement(By.xpath("//*[#text='log in']")).click();
driver.findElement(By.xpath("//*[#id='lgin_edit']")).sendKeys("1234567789");
driver.findElement(By.xpath("//*[#class='android.widget.EditText' and (./preceding-sibling::* | ./following-sibling::*)[#id='text_input_end_icon']]")).sendKeys("qwer");
new WebDriverWait(driver, 120).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#class='android.widget.EditText' and (./preceding-sibling::* | ./following-sibling::*)[#id='text_input_end_icon']]")));
driver.hideKeyboard();
driver.findElement(By.xpath("//*[#class='android.widget.EditText' and (./preceding-sibling::* | ./following-sibling::*)[#id='text_input_end_icon']]")).click();
driver.findElement(By.xpath("//*[#text='Log In']")).click();
driver.findElement(By.xpath("//*[#text='Log In']")).click();
}
#AfterEach
public void tearDown() {
//driver.quit();
}
}
Ok, this is what resolved my issue.
After posting the questino I realized, the button wasn't enabled, that's because the previous input text field is not clicked or something.
All this time I was recording via Appium, but I was manually clicking the keyboard and buttons on mobile phone, not the mobile simulator of appium.
After 2.5 days, I used mouse pointer of my computer to click all the fields and all simulation on the simulator of appium and recorded and re-ran the tests and it worked.
I did try printing out the button state and it was always btn.isEnabled() was returning false.

How can make pycharm confirm that the redirect from mobile app to the mobile browser was done?

Searched everywhere but I fail to find an answer.
Scenario:
Automation script done for an Android application
Pre-req:
Click on a button from the Android application with a Mobile browser redirect
What I want the script to check:
If user was successfully redirected to the Mobile browser by checking if an element from the Mobile browser page is displayed (with a text or link or xpath)
The script is made for the Application but I fail to find the correct code for it to check an element from the browser page
I will post here a small part of code from my automation script for an Android app:
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import time
if __name__ == "__main__":
desired_cap = {
"platformName": "android",
"deviceName": "emulator-5554",
"appPackage": "com.project.ProjectName",
"appActivity": ".SplashActivity",
"automatorName": "UiAutomator2",
}
driver = webdriver.Remote ("http://localhost:4723/wd/hub",desired_cap)
#Get more gold button check
element =
driver.find_element_by_xpath("xpath here")
element.click()
print("Step 12. Get more gold button clicked")
pass
#??????Confirmation that Gold store was open IN BROWSER
wait = WebDriverWait(driver, 10)
element = driver.find_elements_by_xpath("//xpath here,*[text()='Choose your payment method']")
#wait.until(EC.visibility_of_any_elements_located((By.CLASS_NAME, "flx-j-c txt-up")))
for i in element:
if 'Choose your payment method' == i.text:
print('Step 13. User not on Me tab - PASS')
else: print('FAIL to redirect the user')
time.sleep(2)
driver.back()
pass
Error:
selenium.common.exceptions.TimeoutException: Message:
I tried to find the element by xpath, class, by text, there is no id to use for this.
I think the issue is here,
element = driver.find_elements_by_xpath("//xpath here,*[text()='Choose your payment method']")
if you pay attention then you have something like this xpath here in xpath("")
instead it should be :-
element = driver.find_elements_by_xpath("//*[text()='Choose your payment method']")
Now you will have a list here.
print(len(element))
print the size like this or do whatever you wanna do with the list. It's all upto you.
Update 1:
After seeing the HTML, I think this should work for you.
Xpath
//section[contains(#class,'gold-payment-methods')]/descendant::strong
In code :-
element = driver.find_element_by_xpath("//section[contains(#class,'gold-payment-methods')]/descendant::strong")
element.click()

System.out.print with // prints the code Blue. What is the meaning of this?

System.out.println(TAG + " //METHOD_STARTED// - //start_firebase_and_get_userID//");
Why if I write these in my app, it comes in blue in the console after the //?
It appears to be mistaking it for a hyperlink.
//METHOD_STARTED// is a valid protocol-relative URL (domain names don't have to have dots if they're on your local network), and it seems that Android Studio/IntelliJ's link detection is falling for it. Of course, it's not valid in this case, because there's no protocol in the log output for it to be relative to, so really this is a bug.

Not able to send text to Content-desc field using Appium with sendkeys() method

I am trying to automate Google Hangouts app using appium(in java).
I am using Appium CLient v 1.3.7 I am using Samsung Galaxy S5 Android os version 5.0.
I want to send text using element.sendkeys() method to the field having content description as "Type a name,email,number or circle" field. Appium does find the field but after executing sendkeys() command, it does not show anything in the same field. Appium clicks at the left edge of the app.
This field does not have resource-id. I tried element.click() before using sendkeys() but din't help. Any suggestion?
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capa);
WebElement el1 = dr.findElementByName("Type a name, email, number or circle");
el1.click();
el1.sendKeys("0000000");
It does not have name which you are considering , you can identify that element by following way :
WebElement el1 = driver.findElement(By.id("com.google.android.apps.hangouts:id/people_audience_view_chip_container")).click();
el1.sendKeys("0000000");

Android /dev/uinput does not work

I'm trying to control Android by writing data into /dev/uinput. For example, if I enter 'A' on my desktop, the codes will write something according to key_code into uinput and Android should behave like I input an 'A' on the phone. I am following the codes in RemoteInput. I tested on Nexus 4 with JB 4.2 system. All the ioctls return positive results, which means it should work. However, when I put in an 'A', the Android only seems to refresh the virtual keyboard and does not input anything.
First, you need to "register" the supported keys using ioctl(m_fd, UI_SET_KEYBIT, key). For A, you should use KEY_A, which is defined in linux/input.h (#define KEY_A 30) and not KEYCODE_A, which is a different code. In my experience, /dev/uinput on Android works with Linux key codes.
You should:
open /dev/uinput
ioctl(m_fd, UI_SET_EVBIT, EV_KEY) - support EV_KEY event
ioctl(m_fd, UI_SET_EVBIT, EV_SYN) - support EV_SYN event
ioctl(m_fd, UI_SET_KEYBIT, key) - support key - for each keycode that you want to support
create uinput_user_dev structure and populate it, then write that structure to /dev/uinput file descriptor (see below)
call ioctl(m_fd, UI_DEV_CREATE) to create this device; the m_fd will now point to newly created device.
Do monitor logcat output and check if the device will be created successfully. It will take a generic keychar map and key layout, since no keymap is defined. If you want to define it, look into /system/usr/keychars and /system/usr/keylayout.
Create uinput device
uinput_user_dev uidev;
memset(&uidev, 0, sizeof(uidev));
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-test");
uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x1212;
uidev.id.product = 0xabab;
uidev.id.version = 3;
write(m_fd, &uidev, sizeof(uidev)

Categories

Resources