Hello
I've tried searching for an answer on the web since my knowledge regarding Regular expressions is limited, with no luck. Hopefully someone in here can help me.
Long story short.
I need to test a simple function on a web page. Before I can do this I must log in.
I go to the web page
When I go there I get redirected to a signon page:
I have created a script that logs in and test the function.
My issue is this:
If I run the script and the browser still has the user logged in, it does not redirect to the signon page, and the script fails before it begins.
I figured I could use an if/else statement in the beginning of my script:
If logged in --> then run script to log out, and after that start the test
Else -> Start the test
My idea is to check the url for a specific word "login" if this is present I run the 'if' statement, else I continue.
I figured that using regular expressions would be the way to go, and this is what I came up with:
HTML
<tr>
<td>open</td>
<td>wb</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>url</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>"${url}"</td>
<td>urltoString</td>
</tr>
<tr>
<td>echo</td>
<td>${url}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${urltoString}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>re = /(login)/;re.exec(${urltoString})</td>
<td>login</td>
</tr>
<tr>
<td>echo</td>
<td>${login}</td>
<td></td>
</tr>
<tr>
<td>storeTextPresent</td>
<td>login</td>
<td>isPresent</td>
</tr>
<tr>
<td>echo</td>
<td>${isPresent}</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>${isPresent} == true</td>
<td>YesPresent</td>
</tr>
The log gives me this:
- [info] Playing test case BookingCreated
- [info] Executing: |open | wb | |
- [info] Executing: |storeLocation | url | |
- [info] Executing: |store | "${url}" | urltoString |
- [info] Executing: |echo | ${url} | |
- [info] echo: https://testweb.bw.com/sts/identity/login?signin=3c4854ab5612b0e8fbeeb492f3b7
- [info] Executing: |echo | ${urltoString} | |
- [info] echo: "https://testweb.bw.com/sts/identity/login?signin=3c4854ab5612b0e8fbeeb492f3b7"
- [info] Executing: |storeEval | re = /(login)/;re.exec(${urltoString}) | login |
- [info] script is: re = /(login)/;re.exec("https://testweb.bw.com/sts/identity/login?signin=3c4854ab5612b0e8fbeeb492f3b7")
- [info] Executing: |echo | ${login} | |
- [info] echo: login,login
- [info] Executing: |storeTextPresent | login | isPresent |
- [info] Executing: |echo | ${isPresent} | |
- [info] echo: false
1. Why does the value 'login' contain "login,login" ?
2. Why does the 'storeTextPresent' return 'false' ? (since "login" is present in the text, should it not it return 'true')
I might be totally wrong in my way to approach this issue, if anyone have a better solution please share it.