Step the url should match with Behat - behat

I'm testing the step of Mink: Then the url should match "pattern"
My url is some like "/test/34kUñlj" and this is a _blank target. This means that when I click on a link, then it open a new windows and the url is "/test/34kUñlj".
I'm using sahi driver.
The pattern after /test/ is a random hash.
The first problem is: the step the url should match is marked as undefined. I looked at the api of Mink and saw that this step wasn't "" so I tried this: Then the url should match /test/ñljñl23 and still marking it as undefined.
The second: why I follow the new windows that is open?
And finally: how is the pattern of that url "/test/342lñasjf". I use "/test/\d+"
Thanks

a) The mink step is defined with "", so you should use Then the url should match "url"
b) Do you mean "how do I follow the new window that is opened?". If that is what you mean, it cannot be done. It is a problem of testing with sahi: when you open another window, this is not tracked by Mink and the url that Mink sees is the one in the original window. What I did in a similar case is that if the environment is 'test', then I don´t add the "_blank" target so that it opens in the same window. Not a perfect solution, I know
c) The step should be
Then the url should match "/test/\w+"
not "/test/\d+" as this only matches numbers

Related

Is the Selenium IDE test case property "Title" accessible to my script?

For example, if I create a new test case in the IDE, and it appears in the left hand side window pane, then right click that test case and chose "Properties", there are two properties available ... one of them is "Title".
The IDE allows one to create separate titles for each test case, even if you have included the same test case twice.
For example, I might have a script where I want to login twice (just an example only to serve the purpose of this question).
I could provide a title for the first instance of the login.html test case as "1st login", then add some test case, logout, and login again ... then title the second instance of the login.html test case as "2nd Login".
This is very handy. However, I want to be able to access the title value in the test itself. In that way, I might know that I am on the first or second instance of the same test case file.
I know some of you may have other opinions about how to accomplish the goal, but keep in mind, I am only using this as an example ...
I want to find out if the "Title" is available to me programmatically during a test run.
I'm not sure I understand your question, but maybe this can help.
"storeLocation" command is useful to store current selected window's URL in selenium IDE. The web application's URL will be stored into variable "varTitle1" and you will be able to use that variable value anywhere in your script.
*Command - Target*
open - https://www.google.com
storeLocation - varTitle
echo - ${varTitle}
"storeTitle" command is storing title of current opened software web application's title. It will store current selected windows title in to variable "varTitle2".
Command - Target
open - https://www.google.com
storeTitle - varTitle2
echo - ${varTitle2}

What is the working of Browser and Page in QTP/UFT?

I always get a doubt that:
What exactly is the difference between the working of Browser and Page.
I know it is a hierarchy and that stuff, but how does the tool differentiates the browser and page and what is use of having both of them.
For example, if I use descriptive programming, and type:
Browser("title:=Google").Page("title:=Google").something
irrespective of the Browser (which may be IE / Chrome / Firefox) it will use the browser with the title = Google. And same is for the page.
Please elaborate. I am confused.
There's an explanation of what Browser and Page are supposed to represent on HP's blog.
In short Page has no semantic meaning, it is just used in order to organize the object repository more cleanly (so that you don't get hundreds of objects under one Browser object). If you're using descriptive programming (as I see from your example) then the Page has no meaning (since every browser has only one Page) and having a description for the page adds nothing.
I would replace the line with:
Browser("title:=Google").Page("title:=.*").something
Or
Browser("title:=Google").Page("micclass:=Page").something

Selenium IDE - Assert that JavaScript redirect worked after clicking Ajax button

I have a button that executes an Ajax request and then it successfully redirects to another page.
How do I assert that the redirected page was successfully reached?
I have a clickAndWait on the button. But after that..?
you can use verifyTextPresent command to verify a unique lable or text in the redirected page.by that way you can fix you have successfully reached the redirected page.
try like this
command : verifyTextPresent
Target : some unique text in the redirected page.
i think your problem can be fixed by this.
IDE has many assert commands. You can use any of the one and you can achieve the test scope(here the page is navigated or not).
Example:
command : assertTitle
Target : check the title of the page.
In the above he used verifyTextPresent it will check weather the text is present or not in the page and it will continue the next step. If you use assert commands it will proceed the next step when the assert step is passed. Otherwise it fails.
One thing you keep in mind, selenium won't wait for Ajax kind of loading, it will wait for the Page loading. So, you have to put Wait commands explicitly to finish the Ajax loading.
You can get moreassertions when you convert the selenese code into the preferred language and testing framework. You can see that option in the Option tab in the IDE.
For more info on AssertCommands in SIDE

HTML encoded links and anchors

I have a use case where I am setting the page focus to a particular element (having an anchor before it). When a user is not signed in, there is a redirect to the login page and after signing in, the user is redirected to the page in question, with the URL encoded.
I see that a URL of the form link#target works as expected (focusing on the element) while the url encoded link link%23target doesn't. Is this expected behavior?
Edit: If this is the expected behavior, is there a work around to focus on the target? As in, a way around url encode?
Edit adding more info:
Assuming that there is a code
page1.html
... html before the anchor ...
<a name="test">Some code</a>
... html after the anchor ...
I am accessing the page as page1.html%23test. This doesn't work the same way as page1.html#test. Is there a jQuery method to implement this? Would location.hash contain test even after it has been url encoded? I have no control on changing the url encoding.
Edit:
As I knew which named anchor I wanted to go to after page is redirected, I did a
window.location.hash = namedAnchor
to solve the issue. This JS line is output only if a customer is successfully signed in. Solved my issue, though not the generic answer I was looking for. I was looking for a way to avoid escaping of # in url encode.
Yes. Encoding the # as %23 effectively says "I just mean a plain old "#" character, not a URL fragment". The same is true of other reserved characters: escaping them stops them from having special meaning in the URL.
In your case you do want to encode the URL when passing it to your login page as a parameter, but your login page should decode the URL before performing the redirect.
You can both parse this string with PHP or other script language, or with JavaScript using the encodeURIComponent. I wrote an article for that, you can check on http://www.stoimen.com/blog/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/
Hope that can help you. However despite the default behavior you must check with either method.

Selenium Address Bar

Good morning
I am using selenium and I have come up against a bit of a wall.
I am attempting to navigate to another page, by typing in the address bar, however I cant seem to do this when using selenium.
Is this possible?
I am not able to simply put a link on the page that goes to this page.
Cheers Cameron
Short answer: Try the "open" command.
Long answer: Selenium doesn't support "typing in the address bar". It can only control what is IN the page canvas, or more specifically, it can only do what JavaScript can do. In other words, it can change the location, but not by actually typing something in to the address bar. The open command uses JavaScript to change the page's location.
The address bar is where you put the base url,
and to use the open the url you need to use the selenium open command,
EX:
Base URL: google.com
command1#
command = open
target = /