2

I am facing an error in the below line:

dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

--> Unhandled exception type MalformedURLException

The code is:

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

public class dailerTest {

    AndroidDriver dr; 
    @Test
    public void call() {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "G6");
        capabilities.setCapability("platformVersion", "7.0");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.android.contacts");
        capabilities.setCapability("appActivity", "activities.DialtactsActivity");

        dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

    }

}
neomega
  • 712
  • 5
  • 19

1 Answers1

1

The documentation says the URL class will throw such an exception if your String is null, an unknown protocol is specified or no protocol is found.

Try this;

dr = new AndroidDriver(new URL("http", "127.0.0.1", 4723, "wd/hub"),capabilities);

I am not sure if it works, but the URL class offers a constructor that is more suitable for your link. URL class

Edit

The error might be because you haven't handled the possibillity that there might be an exception thrown. You can either declare what to do when an exception is throw by wrapping it in a try-catch statement, or you can add a throws declaration to the method signature.

Robert
  • 277
  • 1
  • 16