Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Selenium IDE, how to get the value of the base url

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:

  1. use a variable in the target;
  2. concatenate a variable and a string?
like image 570
Emilien Avatar asked Feb 04 '10 22:02

Emilien


People also ask

What is base URL in Selenium IDE?

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.

How would you extract the URL in Selenium?

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.


4 Answers

Try this

storeEval|window.document.domain|host
assertLocation|http://${host}/some-page|
like image 195
s_hewitt Avatar answered Oct 23 '22 18:10

s_hewitt


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|
like image 44
Helephant Avatar answered Oct 23 '22 18:10

Helephant


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>
like image 2
freak3dot Avatar answered Oct 23 '22 16:10

freak3dot


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].

like image 1
kirbycope Avatar answered Oct 23 '22 16:10

kirbycope