How to automate native "Search" button in Appium Java - selenium

driver.findElementById("SearchField").sendKeys("bacon");
After sending keys the Native Keyboard opens automatically on IOS.
How can i automate Tap on native keyboard "Search"?
Appium + Java + Selenium + Eclipse

If you are using java-client 3.1.0, you can use this:
((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.ENTER);

Assuming you are automating a native mobile application. then you can easily click on the search button.
driver.findElement(By.Xpath("xpath of search icon")).click();
If you are automating web application then you need to change your context to native like below.
STEPS
Get the current context handles
Save the current context Context to Native
Change the Context to Native
Click on the search button
change the context to default
CODE
driver.getContextHandles();
String currentContext = driver.getContext();
driver.context("NATIVE_APP");
driver.findElement(By.Xpath("xpath of search icon")).click();
driver.context(currentContext);

Not sure if this would be helpful for you since it's been half a year but I did have a similar problem. If I was going to search with "Bruno Mars" in the search field, I would just have appium type in "Bruno Mars\n" and the newline would automatically trigger the search button. However, recently my devices weren't responding to the new line anymore. I winded up downgrading the google keyboard to 4.1.x and I was able to use new line method again. The problem was that the devices had auto updated to to version 5.x. So downgrading the keyboard solved the issue for me.

Related

React Native iOS apps, when tested in Appium UI Automation Inspector tool, unable to read Text values

React Native iOS apps, when tested in Appium UI Automation Inspector tool, unable to read static Text values.
Code:
<Text accessibilityLabel={'home_welcome_text'} testID={'home_welcome_text'}>Welcome Home
Issue:
In Appium Inspector, label field show 'home_welcome_text'. Which is not correct, it should give the text value 'Welcome Home' in the label field.
Note: This issue happens only in iOS builds. Android builds are working as expected.
Your help on this is much appreciated. Thank you.

Recognizing element in an Hybrid App - Android

I am new to Android testing. I am currently trying to automate a scenario. I have attached the snapshot of the app screen:
Scenario:
I need to click on "Clock In".
A screen slides from the bottom as shown in the snapshot.
I need to select an item as shown by the arrow.
The developer is saying that it is a Hybrid app. A lot of confusion here for me as I am able to click on "Clock In", but I am not able to select "DL 380 Memory Upgrade".
Doubts:
How to find whether "DL 380 Memory Upgrade" is in Webview/Native?
If it is an element in the webview, how to locate it? I located "CLOCK IN" as below:
#AndroidFindBy(xpath = "//android.view.View[#resource-id='tab-t0-0']")
private AndroidElement clockInTabBtn;
If its an element in WebView, then its web and you won't find anything in web while searching by resource-id - its native attribute only.
I would recommend to use chrome dev tools for debugging hybrid application.
You can read official docs for setup.
Basically you need:
connect device
go to chrome://inspect/#devices in chrome browser
check phone & allow usb debugging if popup appears
check what webViews chrome spotted and click inspect for the one you need
And now you search for elements and their locators the same way you did in Selenum/Web automation
Don't forget to switch context to WebView in your appium test before you actually searching inside webView.
Good luck!
You can check available view using context and can switch to it using follows code:
Set<string> contextNames = driver.getContextHandles();
for (String contextName : contextNames)
{
System.out.println(contextNames);
//To swicth to webview
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
Please refer this thread for similar issue: https://github.com/appium/appium/issues/7243

How to click the back navigation button of the browser using helium?

I am trying to implement helium in my project. I checked the API doc of helium but I didn't find any command to click the back navigation button of the browser.
In the API doc found solution to launch the browser. Code is as following
startFirefox();
startFirefox("google.com");
So I would appreciate if any one can help me with this. Is it possible to integrate selenium and helium all together?
Well I don't find any way to implement click back navigation of the browser using only helium, So I integrated selenium along with helium
getDriver().navigate().back();
It worked for me
Even Don't find any way to navigate back using helium
getDriver.navigate().back();
Worked for me!!!

Verifying toasts using Appium , and get server reaction to button clicks

i'm new to android automation testing and i recently started to work with Appium.
I use it for android native app automation.
I have 2 question -
is there a way to verify toasts?
the latest posts i saw which referred to this issue are from the mid of 2014
and i wanted to know if there's something new in this subject before i will find another tool to run my tests with (as i understand selendroid can verify toasts).
is there a way to catch the http request which my app sends to the server when i'm pressing a button, during the automatic test?
something like a listener which works in the backround and wait for clicks?
tnx
To verify toast messages you can use one of image recognition libraries. For ruby I use RTesseract together with image processor RMgick
Idea is simple:
make toast message to appear
take few screenshots
iterate over taken screenshots and look for text
You may play with image processing, to increase recognition quality.
Here you can find code snippet which I use in my framework: link

how to navigate to settings in android emulator using robotium?

I am a newbie for Robotium and till then I managed to learn a lot by directly writing test cases for public websites and sorted out several issues from answers in stackoverflow. now, I seemed to hit the wall at this (probably)trivial problem.
I would like to navigate to 'Settings' icon which is inside 'Apps' menu of the android emulator using some sort of 'robotium-solo' method.
This is my failed attempt:
solo.sendKey(KeyEvent.KEYCODE_HOME);
//solo.clickOnImageButton(2); // no success!
//solo.clickOnActionBarItem(2); // no success!
solo.clickOnText("Settings");
solo.clickOnText("Music");
I checked for any KEYCODE_var for home screen 'app' icon but couldn't find one.
There is no useful log message in DDMS to figure out the starting activity when clicked/tapped on that button.s
Please guide me whether my approach is any good and help me with an answer. Thanks.
you can check with getCurrentViews() and have the list of views displayed before clicking the menu button and after clicking the menu button.By comparing them you can get the view of the new views displayed (i.e. settings button).
After getting the view,you can go with solo.clickOnView(ViewNameObtained);
This will solve your problem for sure.
As far as I know, navigating to settings is not possible with robotium. Even if you would be able to go there you cannot perform any other action as Settings are not port of your application. Android Instrumentation allows performing actions only within one package and robotium is only wrapper for that, so it's not able to click outside your application as well.
You can use UI Automator for that.