When you start testing using Selenium Remote Control couple of question start running in your mind... :) like what to test?, for this testing what do we require? , etc......
Stop thinking and start writing test script using following simple steps, it will help you to create a simple test script.
Question: What to test?
Answer: Login with valid gmail account and compose a text mail and send it to the same account.
Steps to test:
1. Open Gmail login page.
2. Verify Gmail login page and "Sign in" panel.
3. Enter valid user name and password.
4. Click on "Sign in" button.
5. Compose text mail and send it to the same gmail account.
6. Go to "Sent Item" and verify the mail is revived or not.
7. Sign out.
Steps 1:
Test environment: (A testing environment is a setup of software and hardware)
- Physical (hardware)
- Logical (software)
The first thing is: Script maker should have following software:
- JDK, JRE (which needs to be 1.5 or later).
- Firefox and firebug.
- Eclipses 3.6 (Available on following link)
- Selenium 1.0.2 (Available on following link)
- Junit:
It is a framework for unit testing. When implementing Selenium Test cases using RC, you can implement using Junit. It is a very powerful testing framework and provides us with features like report generation, batch running, skipping tests etc. Selenium along with Junit and ANT can generate very good Selenium test reports in HTML. You can write the code without using Junit as well but Junit provides features which make our task very easy. Features like running multiple test cases in differnt suites in a particular order, test reports, annotations etc. Junit is very famous as compare to TestNG.
Steps 2:
- Open eclipse
- Create project web-gmail-testing
- Create package "selenium ".
- Create a Java file "GmailLoginTest"
Steps 3:
Once you have done above steps add external JAR files into created java project "web-gmail-testing", these files are as following:
1. JUnit jar.
2. Selenium Remote Control JAR file "selenium-java-client-driver-1.0.2.jar".
Steps 4:
- Start writing code using following PNG files:
- Open created java file "GmailLoginTest" and start writing code:
Please refer the following images :) it will help how to inspect actual location of fields, links, text, etc....
IMP:
XPath: Xpath is a language for finding information in an XML document. Xpath is a syntax for defining parts of an XML / HTML document.
Firebug: Firebug is web development tool that facilitates the debugging, editing and monitoring of any web sites CSS, HTML, DOM.
Image 1: Open Gmail login page
IMP:
XPath: Xpath is a language for finding information in an XML document. Xpath is a syntax for defining parts of an XML / HTML document.
Firebug: Firebug is web development tool that facilitates the debugging, editing and monitoring of any web sites CSS, HTML, DOM.
Image 1: Open Gmail login page
Image 2: After login with valid gmail account.
Start coding for above steps using JAVA :
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.*;
import org.junit.After;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Class name: GmailLoginTest.java
**/
public class GmailLoginTest extends SeleneseTestCase {
public void setUp() throws Exception {
super.setUp();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", " https://mail.google.com/mail/");
selenium.start();type
}
public void testGmailLoginTest() throws Exception {
selenium.open("https://mail.google.com/mail/");
/* Verify Google mail login page header bar */
selenium.isElementPresent("xpath=//div[@class='google-header-bar']");
/* Verify Sign in box and labels and text fields. */
selenium.isElementPresent("xpath=//div[@class='signin-box']");
/* Verify the User Name label. */
String userName = selenium.getText("xpath=//strong[@class='email-label']");
assertEquals(userName, "Username");
/* Verify the Password label */
String password = selenium.getText("xpath=//strong[@class='passwd-label']");
assertEquals(password, "Password");
/* Verify if Username and Password text fields is available then enter the valid username and password.*/
if(selenium.isElementPresent("xpath=//input[@id='Email']")) {
selenium.type("xpath=//input[@id='Email']", "seleniumremotecontrol");
}
if(selenium.isElementPresent("xpath=//input[@id='Passwd']")) {
selenium.type("xpath=//input[@id='Passwd']", "selenium");
}
/* Click on "Sign in" button. */
selenium.click("xpath=//input[@id='signIn']");
selenium.waitForPageToLoad("60000");
/* Verify Login user. */
String loginUserName = selenium.getText("xpath=//span[@id='gbi4m1']");
assertEquals(loginUserName , "seleniumremotecontrol");
/* Write a email and send it to own gmail id */
selenium.click("xpath=//div[@role='navigation']//div[@class='z0']//div");
pause(7000);
/* Enter email address. */
selenium.type("xpath=//textarea[@name='to']", "seleniumremotecontrol@gmail.com");
/* Enter Subject. */
selenium.type("xpath=//input[@name='subject']", "Auto Email");
/* Enter body text. */
selenium.type("xpath=//body[@class='editable LW-yrriRe']", "Hello Selenium User !!!!!!!!!! :) ");
/* Click "Send" button. */
selenium.click("xpath=//div[@class='dW E']//div[@class='dX Cq J-Jw']//div");
pause(7000);
/* Verify the send email into send item box. */
selenium.click("link=Sent Mail");
pause(10000);
/* Verify email id whever you used for testing :) */
String sentItemEmail = selenium.getText("xpath=//tr[@id=':1vc']//td[4]//span[@email='seleniumremotecontrol@gmail.com']");
assertEquals(sentItemEmail, "seleniumremotecontrol");
/* Sign Out the gmail. */
selenium.click("xpath=//span[@id='gbi4m1']");
pause(2000);
selenium.click("link=Sign out");
pause(10000);
/* After Sign out verify the Google mail login page */
selenium.isElementPresent("xpath=//div[@class='google-header-bar']");
}
public void tearDown() throws Exception {
selenium.stop();
super.tearDown();
}
}
--------------------------------------------------------------------------------
Second phase is how to run created test script using selenium.
--------------------------------------------------------------------------------
1. Open command prompt.
2. Go to selenium server package.
3. run command "java -jar selenium-server.jar -port 4444" and press enter.
4. Go to eclipse open test file "GmailLoginTest.java" file.
5. Go to Run -> Run as JUnit test.
Please feel free to ask any question regarding to selenium remote control........
8 comments:
This is really useful information
PLEASE TELL ME THE DEFECT IN THIS SCRIPT:
import com.thoughtworks.selenium.DefaultSelenium;
public class firstnew {
public static void main(String[] args){
DefaultSelenium selenium=new DefaultSelenium("Vasudeva-PC",4444,"*iexplore","http:\\");
selenium.start();
selenium.open("http:\\gmail.com");
selenium.windowMaximize();
}
}
while running above script it is not able to click on compose button on this line.
selenium.click("xpath=//div[@role='navigation']//div[@class='z0']//div");
plx help me ASAP.
Awesome blog dude...
Please keep posting more such information...
Nice blog, kindly update with selenium web driver....
Generally, I don't make comments on sites, however, I need to say that this post really pushed me to do as such thing.
Best Selenium Training Institute in Chennai
Selenium training institute in Chennai
The article is more informative. This is more helpful for our selenium course .Thanks for sharing
Thanks, Experience with various technologies and businesses this is generally helpful.
Still, I followed step-by-step your method in this selenium training
selenium certification
selenium online training Hyderabad
selenium online courses
Post a Comment