Showing posts with label Test Suite. Show all posts
Showing posts with label Test Suite. Show all posts

March 2, 2014

Cross BrowserTesting using Selenium Webdriver and TestNG

March 02, 2014 5
Cross BrowserTesting using Selenium Webdriver and TestNG
This is an attempt to explain the feature of selenium webdriver and TestNG.

Generally we will run a single test case or script at a time. If you want to run  a single test on different browsers it is possible with selenium webdriver and TestNG. Test will be executed parallel in two browsers.

Lets see..how we can achieve this

Prerequisites:

Sample Script:
Create a sample webdriver script using TestNG and in that script define a parameter using @Parameter annotation.

Below is the sample script:

Create TestNG:
Create a testNG.xml file to run your script. Parameter value we can pass it from here.

Below is the sample TestNG.xml file




Run your TestNG.xml file and three browsers will open and script will run on 3 browsers parallel.



February 11, 2011

Test Suite using Test NG....

February 11, 2011 6
Test Suite using Test NG....
Most testing frameworks have the concept of grouping a set of text fixtures into a ’suite’ so that you can execute a number of related tests together.

Creating test suites with Selenium doesn’t appear to be obvious at first. Here’s a simple guide on how to create and execute suites of functional tests:



First create two scripts....Ex:Google1 and Google2


Google1.java
------------------------------------------------------------

package test;


import com.thoughtworks.selenium.*;


import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Google1 extends SeleneseTestCase{
public Selenium selenium;
public SeleniumServer seleniumserver;


@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore","http://");
seleniumserver.start();
selenium.start();
}


@Test
public void testDefaultTNG() throws Exception {


selenium.open("http://www.google.com");
selenium.windowMaximize();
}


@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();


}
}
------------------------------------------------------------

Google2.java

------------------------------------------------------------

package test;


import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;

public class Google2 extends SeleneseTestCase{
public Selenium selenium;
public SeleniumServer seleniumserver;

@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore","http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testGoogle2() throws Exception {

selenium.open("http://www.yahoo.com");
selenium.windowMaximize();
}

@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();

}
}




------------------------------------------------------------


Now Create testsuite.xml file....

To create new XML file ..just right click on package(test--my package name) --->new-->File---testsuite.xml(any name you can give )

Sample XML file looks like this..
TestNG Suite

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite thread-count="5" configfailurepolicy="skip" verbose="1" name="suite" skipfailedinvocationcounts="false" parallel="false" annotations="JDK" data-provider-thread-count="10">   <test verbose="2" name="testsuite" junit="false" preserve-order="false"> 
    <classes> 
      <class name="test.Google1"/>
      <class name="test.Google2"/>
    </classes> 
  </test> </suite>  



------------------------------------------------------------
   

       
  
DONE...........


How to RUN????


Right click on testsuite.xml--->Run as--->TestNG Suite.

Thats it!...your tests will run one after the another.................


Hope you enjoy this post....

December 15, 2010

Test Suite using JUnit....

December 15, 2010 5
Test Suite using JUnit....
Most testing frameworks have the concept of grouping a set of text fixtures into a ’suite’ so that you can execute a number of related tests together.

Creating test suites with Selenium doesn’t appear to be obvious at first. Here’s a simple guide on how to create and execute suites of functional tests:

Here i am using Junit scripts and Test suite()


First create two scripts....Ex:Google1 and Google2

Google1.java

------------------------------------------------------------
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.*;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

public class Google1 extends SeleneseTestCase{

private Selenium selenium;
private SeleniumServer seleniumServer;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}

@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}

@Test
public void testText1() throws Exception {
selenium.open("http://www.yahoo.com");
selenium.windowMaximize();
}
}

------------------------------------------------------------


Google2.java

------------------------------------------------------------
package defaultpackage;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

public class Google2 extends SeleneseTestCase{

private Selenium selenium;
private SeleniumServer seleniumServer;


public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iehta", "http://");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}


public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}


public void testText2() throws Exception {
selenium.open("http://www.google.com");
selenium.windowMaximize();
}
}

------------------------------------------------------------


Here is the test suite....TestSuite1.java
------------------------------------------------------------

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

public class TestSuite1 extends TestCase {

public static Test suite()
{
TestSuite nag = new TestSuite();

nag.addTestSuite( Google1.class);
nag.addTestSuite( Google2.class);
return nag;
}

public static void main(String arg[])
{
TestRunner.run(suite());

}
}
------------------------------------------------------------



Run the TestSuite1.java script ...it will automatically run the Google1 and Google2....

Even though first test case is failed it will run the second one....we can change the order of the test cases...