How to write Espresso view/data matchers in Appium Java Client? - java

I am using Appium to test Android application and today I was instructed to switch from UIAutomator2 to Espresso automator. I realized that it will not be so simple as just changing automator name.
As far as my searching go, Appium with Espresso automator have very little (almost none) documentation for writing selectors (view/data matchers) in Java/Kotlin.
I am trying to find out how to for example rewrite my current method for search by text. It looks like this:
(driver as AndroidDriver<*>).findElementByAndroidUIAutomator("new UiSelector().textContains(\"$text\")")
// Written for UIAutomator2
I tried:
(driver as AndroidDriver<*>).findElement(MobileBy.androidViewMatcher(Json().toJson(
ImmutableMap.of(
"name", "withText",
"args", ImmutableList.of("<text>"),
)
)))
But does not seems to work...
I see in appium-espresso-driver readme that I can search by text and by much more, but I cannot simply find a documentation how to send those commands to Appium Server trough Appium java client.
Any recommendations for docs, or help how to do it? Thanks

Related

Element found on appium studio doesn't work for appium standalone server and vice versa

The element which I am capturing via desktop inspector not working on appium studio and working fine when I run via appium stand alone server ?
-Is there any reason behind that?
-Any solution if I capture element from anywhere it works irrespective of any server?
-How to write relative xpath of below code ?
/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]
I am automating an app using appium, so via desktop inspector I captured some element. and when I ran the code it was working fine.
But for on xpath I used appium studio because in desktop inspector it was an absoulute xpath and it was quite long. but when I executed this script got failed on appium studio however it was working fine on appium standalone server.and same thing happened when I located the element via appium studio and tried to run on appium.
-Captured element cant run on both the server ?
//appium studio
driver.findElement(By.xpath("//*[#id='action_contacts']")).click();--
id -action_contacts
resource id - com.appName.chatapp:id/action_contacts
class - android.widget.FrameLayout
//Desktop inspector
driver.findElement(By.id("Contacts")).click();
accessibility id Contacts
id com.appName.chatapp:id/action_contacts
xpath //android.widget.FrameLayout[#content-desc="Contacts"]
An element could not be located on the page using the given search parameters.
The correct locators would be:
ID: driver.findElement(By.id("action_contacts")).click();
XPath: driver.findElement(By.xpath("//*[contains(#id,'action_contacts')]")).click();, you need to use contains() function in order to make a match on the partial text.

Java Selenium Chromedriver webdriver as fast as possible

I am connecting a standalone program to a website, and I have to read some pages of the website. For first, I used Jsoup, but with this I discovered that some informations that I need are loaded after page load, so I searched for webdrivers. (I am not looking for images or something big, my content are all textual)
Now, i found the ChromeDriver, but it is too slow for my case because it has a lot of options and features.
In my case I need just a step more than the Jsoup possibilities.
It is possible to disable the best part of ChromeDriver options and features to reach this goal?
For example, i saw plugin disabling, but is one by one and is not for every chrome browser on every pc. I didn't found an option like "plugin.disable-all".
Furthermore,in this way I cannot open more than a few instance of chromedriver. In this moment, every instance of the chromedriver is opening a Google Chrome Helper that uses 100Mb of ram.
Hope all is clear
HtmlUnit might be enough for your needs. It does support some Javascript.
It can be used with Webdriver. But might as well be enough on its own
To make your webdriver run faster (but not that much faster), you can run the driver in Headless mode. See these articles for a tutorial on how to go into Headless mode for Chrome.
Before starting the driver, add the --headless argument to ChromeOptions.
Headless mode can speed up your automation by not rendering the browser window, but keep in mind that doing a straight HTTP GET with JSoup would always be faster.
My advice would be to reverse engineer the page a bit more, and see if you can figure out how to query directly whatever the (presumably AJAX) calls are putting on the page. If you can treat those specific requests as an API and only query for exactly what you want, you will be able to get results faster than with browser automation through Selenium.

Is there any option to automate APIs using Java and Selenium webdriver

I have lots of REST APIs to automate. I know that it can be automated using SOAPUI and Groovy/Javascript.
But I am looking for solution to automate APIs using Selenium webdriver and JAVA. I have already searched for similar solution but unable to find.
You can use Selenium webdriver only for browser automation. Webdriver is only for driving the browser like launch, close, maximize, minimize, screenshot the browser etc...during this automation if you need to test API you can send resquest to the required API from any one of the programming language like java, c#, javascript,etc... and you have to receive the response from the API. You have to test you get the expected response for the given resquest. Selenium webdriver is nothing to do with API testing.

Configuration of selenium webdriver with xorg-x11-server-Xvfb

We have developed selenium webdriver script with junit+java using eclipse on window 7. All the scripts are working as expected now we are using this script for load testing using Jmeter. However, while running script system open multiple browser (200) based on user thread and it create system to hang, is there any way to handle this or we can run script without opening browser. I have come across xvfb tool, but not able to get java api for this tool to plugin in eclipse.
We have also tried using HtmlUnitDriver but as it does not support javascript hence the test is getting failed, also we tried HtmlUnit and found same thing.
Note: that we have writen webdriver script to maintain display item of element (autocomplete, image) on screen.
It would be great if anyone can help or provide more inputs on this...
Firstly, do not integrate selenium scripts with JMeter for load testing! It's not a good approach to follow due to the obvious consequences that you have mentioned in your post. I followed a similar apporach in the beginning when I was new to JMeter and selenium but suffered a great deal when it came to running load tests that spawned too many browser instances which killed the OS.
You can go for HtmlUnitDriver or any headless browser testing tools out there with JMeter, but still, they will be running the browser internally in the memory. Moreover if your application is heavily using Javascript, it won't help.
So I would suggest that you record a browsing session with JMeter Proxy and modify the script (set of requests) according to your needs and play those requests alone, with number of threads.
From a higher level, you should be doing this:
Add a JMeter test plan, listeners, thread group and setup JMeter proxy and record a browsing session where you enter something into the autocomplete textbox and you get certain results.
Stop your proxy and take a look at all the requests that come under your thread group.
As far as I know, when it comes to autocomplete plugins, multiple
requests are sent everytime you enter a letter into the textbox. For
example, for the word 'stackoverflow':
Request1: q=s Request2: q=st Request3: q=sta and so on
Here you can simulate this effect by including words such that all
words have the same length which in turn will let you have same
number of requests to be sent to the server.
So in your test plan, you will pass one word per Jmeter thread. You
can pass the words to a request, from a csv file by using jmeter
parametrization.
This will be a much memory efficient way of load testing instead of using selenium with JMeter. I had asked a similar question. You can check out the responses.

Selenium iPhone Simulator Alternative for doing a Test Run

I am using iPhone Simulator in MAC with Xcode to run my tests which I wrote, even if I code first time and if I want to test the code works or not I need to run in simulator is there is any alternative way to do it ? instead of running in simulator even to test a code before the actual Test runs ?
I use Google Chrome with User Agent as iPhone to identify components as my application renders based on the Browser agent.
My initial plan is to call Chrome with pre-defined Profiles and user agent extensions.
Kindly give your suggestions.
There are many emulators out there for the iPhone. Configuring Chrome with User Agents is one of the quickest and easiest.
Maybe implementing your tests with a slicker tool may help reduce this burden? I suggest you take a look at iOS Driver.

Categories

Resources