Selenium – My Learning’s – XPath

XPath: XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium. (Wikipedia)

I recorded one script now and here are the steps:

  1. Open www.flipkart.com
  2. Search for “Software Testing” books
  3. Click on the first search result (link)

The above script looks like – 

After running the above script I did not come across any errors, now I want to search for “Selenium Testing” and want to click on the first search result

Modified script looks like – 

Did you observe that, I have not changed the last line of the script, which says clickAndWait a link? Okay, let me run the script and see the result.

Wow!! It got PASSED without any errors. How it is possible? It is not pointing to the link name, whereas it is pointing to the Path of the link.

Then what we need to modify to make this script working. Add the Xpath of the link in the script. To find the Xpath I used Firebug add-on of Firefox (You can also use XPather add-on). Then I changed the script with Xpath (It looks like)

And yes, now my script is working as intended.

Do you have any other examples for Xpath, please do share with me.

Happy Learning – Happy Testing

Thanks,
Sudhamshu

 

Advertisements

Selenium – My Learning’s – Part THREE

Hello Readers,

This time I was just thinking of learning commands by not recording them, but typing manually into Selenium IDE window. I thought this course might help me to learn additional about commands.

Started typing all the commands which I am familiar with (As said in previous two posts)

Wanted to open Google.co.in – Added the link to “Base URL” as shown

 

What if I run, will it open Google.co.in? No, because I have not mentioned a command to open it. I just mentioned what to open.

After searching for some examples, I found this http://www.qaplanet.in/Selenium-Handbook-by-qaplanet.in.pdf useful. Thanks for the author for helping with testing exercises.

Note: I changed the steps into my own process.

First Exercise:

• Open (www.google.com)

• Type “Sudhamshu Ailineni” in the Google Search Input Box

• Click Search Button

• Verify the Text Present as “Sudhamshu Ailineni”

• Assert the Title as “Sudhamshu Ailineni – India|Linkendin”

 

First_Exercise
open /
type id=lst-ib Sudhamshu Ailineni
click name=btnK
verifyTextPresent Search
pause 1000
verifyTextPresent Sudhamshu Ailineni
assertTitle Sudhamshu Ailineni – Google Search

 

Why I did add a “pause” command at line 5, because “Sudhamshu Ailineni” text takes some time to load and if I have not been added that command, it will through an error message as “False”.

 

Second Exercise:

  1. Open Firefox Web Browser
  2. In the address bar, Type http://www.yahoo.com
  3. In the search input button, Type “Sudhamshu Ailineni”
  4. Click on the “Web Search” submit button
  5. Wait for Search Results to come on “http:/search.yahoo.com”
  6. Verify “Sudhamshu Ailineni” text is present anywhere in the search results: (Select and highlight anywhere in the search results page, “energy efficient” text is present.)

 

Second_Exercise
open /?p=us
pause 1000
type id=p_13838465-p Sudhamshu Ailineni
clickAndWait id=search-submit
verifyTextPresent Sudhamshu Ailineni | LinkedIn

 

You can observe that, it is opening that “/?p=us”, what does it mean? What happens if I change this to “/”. Let me change and see the results. It is not finding the target of the application and getting timed out after 30000 ms J

 

Third Exercise: 

  1. File à New Test Case (Make Selenium IDE in Record Mode)
  2. Open http://www.ge.com
  3. Go all the way down, click on the “Contact Information” link
  4. Click on “Feedback & Inquiries” link
  5. Consumer/Other (Leave the default option)
  6. Select a Subject (Other)
  7. Select a Country (India)
  8. Email (type test@test.com)
  9. Comments or Questions (type Test Comments)
  10. Submit (click once)
  11. In the result page, highlight “Thank you for taking the time to contact GE”
  12. Right Click and Select waitForTextPresent “Thank you for taking the time to contact GE”
  13. Highlight “Feel free to continue browsing.”
  14. Right Click and Select VerifyTextPresent “Feel free to continue browsing.”
  15. Right Click on “GE.com Home Page” link and Select verifyElementPresent “link=GE.com Home Page”

 

Third_Exercise
open /
clickAndWait link=Contact Information
pause 500
clickAndWait link=Feedback & Inquiries
waitForTextPresent Subject (Mandatory)
select id=contact_subject label=Other
select id=contact_country label=India
type id=contact_email test@test.com
type id=contact_comments Test Comments
clickAndWait id=submit_button
waitForTextPresent Thank you for taking the time to contact GE
verifyTextPresent Feel free to continue browsing.
verifyElementPresent link=GE.com Home Page

 

I am in hunt of finding more exercises; if you have something then please share with me, let us automate them using Selenium IDE.

P.S: I will write more on Locating Elements, Useful Selenium Add- Ons and much more after my exploration and learning

 

Happy Learning – Happy Testing

Thanks,
Sudhamshu

Selenium – My Learning’s – Part TWO

This time I will show you my learning’s of SELENESE – Selenium Commands

I recorded the script for creating a WordPress blog.

Steps are as follows:
1. Open WordPress website (https://en.wordpress.com/signup/)
2. Fill in all the required fields
3. Submit

Result:
Should send an email with the activation link.

So, here is the script displayed after recording the above steps:


Before playing the above script, I cross verified and observed the following issues:
* Not recorded the Step for “Username”
* Not recorded the Step for “E-mail Address”

Because, “Username” is the value which it has taken automatically from the Blog name while I am recording. Also the “E-mail Address”, it is not recording because when we type some text it searches in their Database and throws an error message to enter the valid email address, this is stopping Selenium to record the step. (As shown in the screenshot)

How I made my script work?

After exploring I learned about “type” and “typeAndWait” command. They are something similar like “click” and “clickAndWait”

From the initial script, I understood that each field in the page has an id and that should be inserted to make my script work.

Command Target Value
type id=user_name sudhamshu2016

 

 

“Username”– I added the command as above

 

Okay, you might get confused of how and from where to get id. Right click you mouse on placing the cursor on the field you are searching for. You will get some options as like shown below:

Did the same for “E-mail Address”

Command Target Value
type id=user_email ratnadeepu568912@gmail.com

 

 

 

And my script looked like this after playing.

Still exploring a lots of SELENSE commands, if you start learning Selenium you might know more about SELENSE, because your context may vary from mine.

While I was recording the script for Gmail Registration, I found some issues with the Hidden drop-down values and CAPTCHA. After exploring a lot I found that there is no way to record CAPTCHA with Selenium IDE. Just to add a “pause” command and type in manually.

But I still did not have a solution of how to record the script for Hidden drop-down values (Still exploring).

Some other commands which I tried to insert after exploring:

  1. I want to check the Title of the Webpage before my test runs, so I used “assertTitle”.
  2. Again I want to check the Title of the Webpage before my test runs, so I used “verifyTitle

How they both are different?
I observed that when I add “verifyTitle” my script is running without failing at that step and showing me the results at end and “assertTitle” is halting the script where it went wrong

When you think in different ways of automating, you might be using more commands. Write the steps before you automate, it helps you automate better.

P.S:  Dear reader if you have a solution to record the Hidden drop-down values, please share it with us.

Happy Exploring – Happy Testing

Regards,
Sudhamshu

Selenium – My Learning’s – Part ONE

Selenium is a tool which I’m using for automating the web applications. For example my testing has to create several users with different data, every time it takes a few minutes for creating a User manually; hence I automate this process to test. (It helps me to test faster)

Selenium Integrated Development Environment (aka) Selenium IDE – It is an add-on for Mozilla Firefox (I am using 1.7.2 version of Selenium IDE). Download it and restart your Firefox browser to start using.

My first script for record and play:

  1. Open Google.co.in
  2. Search for “Sudhamshu Ailineni”
  3. Click on the first link from the search results

The IDE window looks like this after recording the above steps:
The Red icon in the below screenshot is used for recording the script and the blue arrow icon is used for playing the script (Do you want me to put screenshots for these?)

I have ran the script and got the following results

Error – Link not found.
Why it is throwing this error?
It was fine while recording; now I started my exploration on this and expected that it should be clickAndWait but not click.

In my script, the fourth command

Command Target Value
click id=gbqfb

Here “id=gbqfb” is searching for “Sudhamshu Ailineni”, but before the page loads it is again searching for the first link available in the page.
So, I changed my script as follows:

I changed the command from “click” to “clickAndWait” and found that it is getting timed out after 30000ms. Because, two “clickAndWait” commands one by one.

So, I changed the command back to “click” and added a “pause” command (As shown in the screenshot below) and it got worked.

It was my first learning about Selenium. Now, after recording this scenario I am asserting and verifying with more commands, I will share them in the next post.

Hope, my learning might be a help to the beginners who are planning to learn Selenium.

Further Reading:

Selenium – Web Browser Automation
Selenium IDE Plugins
Downloads – Selenium
Selenium (software) – Wikipedia, the free encyclopedia
Selenium tutorials for beginners/newbie
Selenium Tutorial for Beginner/Tips for Experts
Selenium Tutorial
Selenium Documentation

Happy Learning – Happy Testing

Thanks,
Sudhamshu