Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use appium for testing web apps?

Tags:

appium

The application I am testing is a web based app. Is it possible to use Appium to test this? On their website it states "Appium is an open source test automation framework for use with native and hybrid mobile apps."

So I am unsure if this will work for my web app as it is not a native app or hybrid app.

Can someone enlighten me?

Thanks!

like image 216
user1523236 Avatar asked Oct 16 '13 20:10

user1523236


People also ask

Which type of applications does Appium not support?

Answer : Appium does not support testing of Android Version lower than 4.2. Limited support for hybrid app testing.

Is Appium better than Selenium?

Appium has the ability to automate all types of web applications along with mobile applications. Selenium can automate all types of web applications but it cannot automate mobile applications.

What can be tested with Appium?

Appium is an open-source test automation tool used for testing mobile applications. It allows users to test various types of mobile applications (such as Native, Hybrid and Mobile Web) using standard WebDriver library. There are three types of Mobile Apps: Native: Native apps built using iOS, Android, or Windows SDKs.

Will Appium work for mobile browser automation?

Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS, Android, and Windows.


3 Answers

First of all, you need to know what kind of web application you want to test. According to information from Saucelabs

there are three types of web application:

  1. Native application
    Yes, you can test it using Appium which is a popular tool for mobile testing.
  2. Hybrid application (Native + webview)
    Yes, you can test it with Appium but with a little trick that you may need to change the context to switch to webview mode. appium.io
  3. Web app (app that is accessible from browser installed on your mobile device, not the one you can download and install)
    Yes, and the details are at appium.io too.

Besides, there is actually another type of app: hybrid app, but with customized webview.
I've been struggling with it recently because I have trouble to find and switch to the webview mode.

like image 88
wenwen Avatar answered Oct 24 '22 13:10

wenwen


I have found Appium to be very cumbersome in testing mobile web applications due to the fact that touch actions are not well supported. From a Java standpoint, I have found there to be two main options for talking to Appium: the Selenium RemoteWebDriver and the AppiumDriver from the Appium Java client.

Selenium RemoteWebDriver

Until now I have been able to test our web app on an Android device using the selenium RemoteWebDriver and RemoteTouchScreen. Using Selenium 3.6.0 and Appium 1.6.5, I have tested 4 different methods to click an element:

webDriver.findElement(locator).click();
new Actions(webDriver).moveToElement(findElement(locator)).click().perform();
new RemoteTouchScreen(new RemoteExecuteMethod(webDriver)).singleTap(((Locatable)webDriver.findElement(locator)).getCoordinates());
new TouchActions(webDriver).singleTap(locator);

On Android, the first 3 methods work, but 4 throws a 'not supported' exception. I have opted to use method 1 for clicks/taps and 3 for gestures.

On iOS, methods 1, 2 and 4 throw a 'not yet supported' exception and method 3 does nothing. Since I was not prepared to invest the time to troubleshoot that, we are only testing on Android for now in the hopes that Appium will be improved and iOS will be better supported.

Appium Java client

My experience with the Appium java client (version 5.0.4) was worse still. There doesn't seem to be a comprehensive tutorial on how to do touch actions, only a few code snippets flying around on the interwebs. So my answer to this question is an attempt at creating one.

First instantiate the driver and navigate to a page:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Samsung Android S8");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("platformName", "Android");
MobileDriver appiumDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

appiumDriver.navigate().to("https://duckduckgo.com");

Then perform a touch action:

new TouchAction(appiumDriver).tap(appiumDriver.findElement(By.id("search_form_input_homepage"))).perform();

This results in: org.openqa.selenium.WebDriverException: Method has not yet been implemented

From this forum post I deduced that I have to switch context to be able to do touch actions. Attempt two:

appiumDriver.context("NATIVE_APP");
new TouchAction(appiumDriver).tap(appiumDriver.findElement(By.id("search_form_input_homepage"))).perform();

That works. However, only for the By.id selector. I could not find any other selector that works when in the NATIVE_APP context. And since most elements in our web site lack an id, I need an xpath selector. Attempt three:

appiumDriver.context("NATIVE_APP");
new TouchAction(appiumDriver).tap(appiumDriver.findElement(By.xpath("//*[@id=\"search_form_input_homepage\"]"))).perform();

Which resulted in: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

Other workarounds that I could think of, such as selecting the WebElement in the CHROMIUM context and then carrying over the location to the NATIVE_APP context is not an option since the coordinate systems differ (browser pixels vs screen pixels).

And don't forget to return to the default CHROMIUM context after each touch action. So the complete code of the only working example becomes:

try {
    appiumDriver.context("NATIVE_APP");
    new TouchAction(appiumDriver).tap(appiumDriver.findElement(By.id("search_form_input_homepage"))).perform();
} finally {
    appiumDriver.context("CHROMIUM");
}

At this point my conclusion is that testing mobile web applications with Appium is not quite there yet.

like image 41
Anne van der Bom Avatar answered Oct 24 '22 13:10

Anne van der Bom


Yes, I'm pretty sure you can, have a look here:

EDIT: outdated link fixed link to appium doc

Also, a related question here

like image 45
qefzec Avatar answered Oct 24 '22 13:10

qefzec