selendroid / selendroid

"Selenium for Android" (Test automate native or hybrid Android apps and the mobile web with Selendroid.) Join us on IRC #selendroid on freenode. Also confirm you have signed the CLA http://goo.gl/pAvxEI when making a Pull Request.
http://selendroid.io
Apache License 2.0
889 stars 435 forks source link

It is impossible to use URL with "and-activity://" scheme #326

Closed smiklosovic closed 10 years ago

smiklosovic commented 10 years ago

@DominikDary @selendroid

Hi,

I am not sure if you are aware of this but I can not use URLs which has the form like

URL url = new URL("and-activity://start.this.activity")
browser.get(url.toExternalForm());

I can use it only like this

browser.get("and-activity://start.this.activity")

This is very inconvenient since we are doing some new API where we want and need to be able to use that URL form and not just that string which is not so flexible anyway.

The problem with that custom URL scheme is that it is not supported by Java's URL. Check that (1). You have to register that URL handler with custom scheme name into your code as described.

I do not mind at all if you continue to use string based form - it is irrelevant from my point of view. However I can not use that form "and-activity" string with dash because from (1) it is clear that there needs to be package with that name and I can not use dash in a package name - it is restricted by Java itself.

For that matter, all I need to change is that dash to another string, like "_" - by doing that, I can create package hence I can register my own URL handler and finally use that URL in normal way.

WDYT?

http://mjremijan.blogspot.cz/2012/02/create-your-own-java-url-handlers.html

lukeis commented 10 years ago

This really has nothing to do with Selendroid's implementation of WebDriver, as you point out it's Java's implementation of the URL object that is causing the problem. Feel free to do whatever you think is necessary to work around the limitation.

And if you need any changes to the RemoteWebDriver Java implementation you'll need to make a Pull Request (or log an issue) with the Selenium project.

smiklosovic commented 10 years ago

@lukeis Huh ... what a response man ...

I am asking for nothing but changing of one letter of that scheme. You are obviously not compatible with Java, not me. How am I suppose to make custom URL scheme when it is not possible?

If I am right, that "and-activity" thing is invention of Selendroid, isn't it? Why you just can not change that one letter? If I am not wrong, it is actually your bad. Sorry if I am not right. I am not going to make any pull request to Selenium since it has nothing to do with it.

Use your Strings as you want, I do not force you to use URL right now at all, but please, do not restrict people to use it properly.

$ cd selendroid
$ find . -type f -name '*.java' | xargs grep 'and-activity' |  \ 
tr -s " " | cut -d" " -f1 | uniq | wc -l
10

10 files to change. Work for 5 mins. Do you want me to change it for you and send a PR?

https://github.com/selendroid/selendroid/blob/master/selendroid-server/src/main/java/io/selendroid/server/model/SelendroidNativeDriver.java#L35

kpiwko commented 10 years ago

@smiklosovic According to URI RFC, dash ('-') can be included in URI protocol scheme name: http://tools.ietf.org/html/rfc3986

If http://docs.oracle.com/javase/7/docs/api/java/net/URLStreamHandlerFactory.html does not allow it, please file a bug in JDK.

That said, we can still use URI instead of URL, right? We can inject URI instead of URL in Droidium.

Benbbe commented 8 years ago

I think that you are using the default android Browser as AUT. You should use this code

driver = new SelendroidDriver(aURL, caps); driver.switchTo().window("WEBVIEW_0");

you can get the entire views of the app using this : Set handles = driver.getWindowHandles();