Search code examples
c#seleniumautomationnunitappium

Appium not working with chrome browser (Testing web mobile apps)


I'm using Appium, the test automation tool for native and hybrid apps on mobiles to test a mobile web application. So I'm using chrome to be the browser and I configured everything, even I tried for an application on the mobile itself(native) and everything worked.

The problem comes when I try to test a mobile web app, the web page opens with data; and crashes immediately and the tests couldn't run.

Here's a snap of my code:

namespace AppiumTest
{
[TestFixture]
public class Appium_Test
{
    //public IWebDriver driver;
   private AppiumDriver<AndroidElement> driver;

    [SetUp]
    public void Setup()
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.SetCapability("device", "Android");
        capabilities.SetCapability("browserName", "chrome");

        capabilities.SetCapability("deviceName", "Huawei Mate 8");
        capabilities.SetCapability("platformName", "Android");
        capabilities.SetCapability("platformVersion", "6.0");

        //For mobile web application 
        driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
    }

    [Test]
    public void Browser_Test()
    {

        driver.Navigate().GoToUrl("www.github.com");
        driver.FindElement(By.ClassName("octicon octicon-three-bars")).Click();

    }


    [TearDown]
    public void Teardown()
    {
        driver.Quit();
    }

}

}


Solution

  • Install the latest Chrome version to your device/emulator (to avoid the infinite loop and Chrome crashing on start which can be caused by the not supported Chrome version in the chromeDriver inside Appium) and use the following capabilities:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554";
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");`
    

    The key to the right capabilities lies in the following package:

    io.appium.java_client.remote.MobileCapabilityType`
    

    If you don't use it, you will use the basic selenium capabilities which are not prepared for that kind of usage.