Is it possible to retrieve the value of the base url from inside a Selenium script (a plain HTML-saved script from Selenium IDE)?
What I'm trying to do is verify the current url using assertLocation
. But assertLocation
returns the absolute url. I would like to compare the current url to a relative url without having to use an *
at the start of the url.
I'd like to have access to the base string because I want to be able to run the tests on different sites (various dev sites + production site), but if I use the *
I can not check for the root page (*/
would be true for each page that ends with a /
...)
This is what I currently do:
|assertLocation | */some-page | |
This is what I'd like to do:
|assertLocation | baseURL + "/some-page" | |
Note: is it even possible to:
After creating a new project you will be prompted to name it and then asked to provide a base URL. The base URL is the URL of the application you are testing. It's something you set once and it gets used across all of the tests in this project.
We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.
Try this
storeEval|window.document.domain|host
assertLocation|http://${host}/some-page|
You can also open your base page and use storeLocation to put the current location into a variable:
|open|/||
|storeLocation|host||
|assertLocation|${host}somepage.html
Bonus: here's how I figured out the corresponding SSL url
|storeEval|window.document.location.toString().replace(new RegExp("^http://([^:]+):80"), "https://$1:40");|hostSSL|
The above solutions cause issues with my development environment being on a non-standard port. This solution may also help with https. If you truly want the base url:
<tr>
<td>storeEval</td>
<td>selenium.browserbot.baseUrl</td>
<td>baseurl</td>
</tr>
<tr>
<td>echo</td>
<td>${baseurl}</td>
<td></td>
</tr>
Using Selenium IDE, this is do able without storing the $(host) value.
Command: open
Target: */login
Value:
This snippet string-match patterns available in the Selenium Core [Source].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With