Reputation: 169
I use AppiumLibrary with RobotFramework to test web browsing on Android. In several of the test, I need to find out what is the current URL that the user has been directed to after clicking on a link.
The basic sample test case is:
Test Appium
AppiumLibrary.Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=0815f853b6d22c05 browserName=default
AppiumLibrary.Go To Url https://www.amazon.com/
sleep 5s
${current_url} get current url
log to console ${current_url}
Unlike SeleniumLibrary, AppiumLibrary does not have a keywork to do this, so I have to create my own keyword for get current url in python. I have tried several things looking at the AppiumLibrary source code and also the Appium-Python-Client module that implements the Appium Webdriver for python. But I have not found how to get the current url that chrome is showing to the user. Any hints on where I should look to find a solution?
Upvotes: 0
Views: 2653
Reputation: 169
I could not find how to get it working with a new keyword. Basically, I could not find how to access the Selenium driver within the Appium driver that implements a method for that, but I got a much simple and elegant answer from katchdoze in the AppiumLibrary channel of slack robotframework. It is as simple as:
Test Appium
AppiumLibrary.Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1 deviceName=0815f853b6d22c05 browserName=Chrome
AppiumLibrary.Go To Url https://www.amazon.com/
sleep 5s
${current_url} execute script return window.top.location.href.toString()
log to console ${current_url}
Hope it helps others.
Upvotes: 1
Reputation: 849
I'm not familiar with Appium, but from what I know of Robot framework the following should work:
AppiumExtended.py
from appium import webdriver
def get_url():
url = driver.current_url()
return url
testScript.robot
*** Settings ***
Library /path/to/AppiumExtended.py
Library Other libraries
*** Test cases ***
Test to get url
${url} Get Url
Log to console ${url}
Upvotes: 0