Showing posts with label Selenium. Show all posts
Showing posts with label Selenium. Show all posts

Tuesday, June 18, 2013

How to generate Report in TestNG?

Generating reports is easy in TEstNG compared to other frame works. TestNG will generate reports
automatically. After running the script just refresh the project.

Right click on Project and click Refresh…then u can see a new folder test-output..expand that folder you

can see INDEX.html and emailable-report.html.

Test Case using TestNG

package Pract;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class FirstTNG {

public SeleniumServer seleniumServer;//Create a variable
public Selenium selenium;//Create a variable

@BeforeClass
public void beforeClass() throws Exception
{
seleniumServer=new SeleniumServer();//Create an object
seleniumServer.start();//start selenium server
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "http://"); //Pass arguments to selenium
selenium.start();//srat selenium server
}
@Test
public void testFirstTNG() throws Exception
{
//open google page
selenium.open("http://www.google.com");
//maximize window
selenium.windowMaximize();
Thread.sleep(5000);
}
@AfterClass
public void afterClass()
{

//stop selenium
selenium.stop();
//stop selenium server
seleniumServer.stop();
}
}

How to Install testNG ?

Go to tolls --->install new software

Install window will be opened.Click on ADD button.
In Add repository window –Enter names as TestNG and URL http://beust.com/eclipse

Click OK.

Select TEstNG and click Next. And again click Next next..after installing testing just restart Eclipse to

reflect the changes.

What is TestNG?

TestNG is Testing Framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use.

First Java Program for Selenium

public
class FirstJavaPro {
/**
*
@param args
*/
public static void main(String[] args) {
System.
out.println("Hello Shahadat Khan");
// TODO Auto-generated method stub
}
}

Basic java Program for Selenium

package
FirstPrograme;
public
class Car {
public void Start()
{
System.
out.println("car is starting");
System.
out.println("car is starting");
}
public void Stop()
{
System.
out.println("car is stoping");
System.
out.println("car is stoping");
}
/**
*
@param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Car c =
new Car();
c.Start();
c.Stop();
}
}

Basic Java Programe for Selenium

package
practice123;
public
class class123 {
public void start()
{
System.
out.println("its staring now");
}
public void stop()
{
System.
out.println("its stoping now");
}
/**
*
@param args
*/
public static void main(String[] args) {
class123 c =
new class123();
c.start();
c.stop();
// TODO Auto-generated method stub
}
}

Basic Java Program for Selenium

public
class Car {
public void Start()
{
System.
out.println("Car is starting");
System.
out.println("Car is starting");
System.
out.println("Car is starting");
System.
out.println("Car is starting");
}
public void Stop()
{
System.
out.println("Car is stopped");
System.
out.println("Car is stopped");
System.
out.println("Car is stopped");
}
/**
*
@param args
*/
public static void main(String[] args) {
Car C =
new Car();
C.Start();
C.Stop();
// TODO Auto-generated method stub
}
}

Baisc java Programe for Selenium

import
java.util.Arrays;
import
java.util.List;
public
class Basic1 {
/**
*
@param args
*/
public static void main(String[] args) {
// boolean value
boolean a=true;
String arr[] = {
"a","b","c","d","e"};
System.
out.println(arr[1]);
List<String> li = Arrays.asList(arr);
for
(String s: li)
{
System.
out.println(s);
}
System.
out.println(a);
 
}
}

Basic Java Program for Selenium

Concept of Class and Objects


public
class
Audi extends Car {
public void Color()
{
System.
out.println("color is black");
}
public void Start()
{
System.
out.println("Audi is start");
}
/**
*
@param args
*/
public static void main(String[] args) {
Audi a=
new Audi();
a.Color();
a.Start();
a.Stop();
// TODO Auto-generated method stub
}
}

Friday, June 7, 2013

How to check a check box in Selenium RC

To check a Check box on web page please use the below command.
Check a toggle-button (checkbox/radio)
Parameters:
locator an element locator
Usage:
Selenium.click(“locator”); or Selenium.check(“locator”);
Selenium.click(“id=123”); or Selenium.check(“id=123”);

How to type a word in text box in Selenium RC

To type a word in text box or text area we have to use the below command.

Syntax:

Sets the value of an input field, as though you typed it in.  Can also be used to set the value of
combo boxes, check boxes, etc. In these cases, value should be the value of the option selected,
not the visible text.
Parameters:
locator an element locator
value the value to type
Usage:
Selenium.type(“locator”, “value”);
Selenium.type(“id=123”, “selenium”);
For sample script, please go through the script TextBox.java

Thursday, June 6, 2013

How to Capture screen shot with failure?

public Scroll()

{
setCaptureScreenShotOnFailure(true);

}

How to capture snap shot in selenium?

selenium.captureScreenshot(filename);

Captures a PNG screenshot to the specified file.
Parameters:
filename the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"

Tuesday, June 4, 2013

Element Locator in Selenium

Element Locators tell Selenium which HTML element a command refers to.

The format of a locator is:  locatorType=argument
Example: - (“link=click”)

id=id
Select the element with the specified @id attribute

name=name
Select the first element with the specified @name attribute.
  username
  name=username

xpath=xpathExpression
Locate an element using an XPath expression.
  xpath=//img[@alt='The image alt text']
  xpath=//table[@id='table1']//tr[4]/td[2]
link=textPattern
Select the link (anchor) element which contains text matching the specified
pattern.
  link=The link text

How to Create Class in Selenium

In the eclips

Go to File – New –class
Give  Name  First  and  click  the  check  box  public  static  void  main  (String  []
args) click Finish

Thanks,
Shahadat Khan

Monday, June 3, 2013

How to to create selenium server

Now need to create selenium server…

Go to RUN

External Tools

External tools configuration…

There click Program---u will get new configuration window.
Give name selenium server (any name you can give).
Location  ---click  on  Browse  file  systems.
F:\Selenium_Scripts1\jdk1.5.0_11\bin\java.exe
Working Directory--- Browse file system --- F:\ Selenium_Scripts1\lib.

Arguments -
 -jar selenium-server.jar
Click Apply and Run…

How to Create Java Project in Selenium

Procedure of Creating Java Project

1. File—New—Java Project
2. Give Project name (Selenium_scripts)
3. Click Configure JREs in that screen. You will get a new window.
4. Click Add—Standard VM
next.

JRE Home—we need to specify path.
Click  directory—browse  the  path  where  you  created  the  folder

(F:\Selenium_scripts1\jdk1.5.0_11\jre)

All jar files will be added.. click Finish and click OK

Click finish on the open window (New Java Project window)

You can see the new project Selenium_scripts in eclipse window.

Now Right click on JRE System Library[Java SE-1.6]
Select Build Path-configure Build Path.
A new window will be opened. Select Libraries tab and click Add External Jars
Button.
Select path F:\demo\lib and select all 4 Jar files click OK.
You can see all Jar files under Libraries Tab.
Click Ok.

You can see the Referenced Libraries

then everything is done.

what is the Procedure for set up of Selenium in eclicps

1.  Create an empty folder (Selenium_Scripts1) in F drive-no need to create in F
drive you can create folder in any folder.

2.  Create an empty folder lib in Selenium_Scripts1 folder.

3.  Install  jdk1.5.0_11,  copy  the  jdk1.5.0_11  folder  which  is  in  c  folder
(Generally it will be installed in “C” Drive-- C:\Program Files\Java) and paste
it in Selenium_Scripts1 folder.

4.  Paste the 4 Jar files (junit-4.5, jxl, selenium-java-client-driver, and seleniumserver) in lib folder.

5.  Open eclipse (F: \eclipse\eslipse.exe)
After that click on OK.

How to set up Selenium in Eclipse

1. Eclipse (Version 3.5.2) –

http://www.eclipse.org/downloads/
wnloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip

2. Jdk 1.5.0_11 or above

http://java.sun.com/javase/downloads/index_jdk5.jsp
3.  4  Jar  files  (junit-4.5,  jxl,  selenium-java-client-driver,  seleniumserver)

please see the whole procedure in next post.