views:

310

answers:

2

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?
+3  A: 

Try this

storeEval|window.document.domain|host
assertLocation|http://${host}/some-page|
s_hewitt
Thanks, it worked just fine!As the production site uses port 80 but the dev sites use custom ports, I used the following:storeEval | window.document.domain | hoststoreEval | window.location.port | portassertLocation | regexp:http://${host}(|:${port})/some-page$(sorry for the bad formatting)
Emilien
A: 

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|
Helephant