If we want to run a Selenium Script across multiple machines parallelly we are using Selenium Grid.
Using Selenium web driver we can achieve this parallel execution with the help of Remote Web driver class and starting Standalone jar on the remote machine(remote machine may be your local some times).
But with this approach you can run the script in multiple browsers in the same
machine.
The prerequisites to implement this using web driver are
1.Browsers to be installed in the machine
2.Standalone Selenium Server jar has to be started.
Here is the sample code
import static org.junit.Assert.assertTrue;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class GoogleTest {
public static WebDriver driver;
@BeforeClass
public static void main(String args[]) throws Exception{
DesiredCapabilities browsers[] ={DesiredCapabilities.firefox(),DesiredCapabilities.internetExplorer()};
for(DesiredCapabilities capabilities :browsers){
System.out.println("Executing Google Test in"+capabilities.getBrowserName());
driver =new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
driver.get("http://google.com");
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
assertTrue(driver.getTitle().contains("cheese!"));
}
}
}
Thursday, March 29, 2012
Monday, February 6, 2012
WebDriver Backed Selenium---Selenium RC Integrated with WebDriver
Selenium Launched its version2 and they named it as Webdriver.The working and api of this webdriver is quite simple when compared with the Selenium RC which is implemented on JavaSCript and whose api is quite complex.
Many people started working in RC and they are getting familiar with this api, Thought works released their version 2 suddenly which is different from their version 1 .This makes the selenium testers a bit confusion.
Later in their second version they integrated Selenium RC api and they named it as Webdriver backed selenuim,using which testers can write their Test cases using RC as well as Webdriver apis.
Monday, January 9, 2012
Clustering atechnique for improving test case Prioritization
Providing a quality product is a challenge for every originization.Different organizations follow different approaches for improving their quality standards,but for every approach a TestPlan and testcases are needed.
Consider an application which is having some hundreds of Test cases,if we need to perform a sanity test over the application ,How can we test??
Consider an application which is having some hundreds of Test cases,if we need to perform a sanity test over the application ,How can we test??
What are the test cases that we need to test in sanity testing??'
For each and every test case we will assign some priority and we start testing high priority test cases in this situation.Now the question is How can we assign priority??
There are many ways to assign priority but one efficient technique is to use Clustering approach(Data Mining concept).
Clustering is a Datamining technique in which the objects(for us test cases)are divided into groups and objects in the same group will have similar futures.These groups are also called clusters.
How can we performing clustering on test cases??
The closest test cases in terms of code coverage are grouped into cluster.
How can we prioritize those test cases??
We can Prioritize them using
1.Code COverage
2.Code complexity
3.Fault History Information.
"A clustering approach to improve testcase prioritization" by Ryan Carlson an employee of "Microsoft" explained this process in IEEE international conference on software Maintenance.
Tuesday, November 1, 2011
RemoteWebDriver cannot be cast to org.openqa.selenium.Takes Screenshot,error in Selenium
Finally I am running Selenium Scripts in a Remote Machine.This time I need a Screen Shot of the Browser which initiated in Remote Machine.
So I googled and found a piece of code which Can do this task for me.This is the Code.
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
I appended this to my script and executed the script,I got the following error in logs.
org.openqa.selenium.remote.RemoteWebDriver cannot be cast to
org.openqa.selenium.TakesScreenshot.
So finally i found a fix for this error,and got screen shot of the remote machine.Here is the code which worked for me.
public class GoogleTest extends TestCase{
@Test
public void testSearch() throws Exception {
URL url = new URL( "http", "localhost", 4444, "/wd/hub" );
DesiredCapabilities capabilities =DesiredCapabilities.internetExplorer();
capabilities.setJavascriptEnabled(true);
WebDriver driver = new RemoteWebDriver(url,capabilities);
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
Thread.sleep(3000);
assertTrue(driver.getTitle().contains("Cheese!"));
WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot)augmentedDriver).
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(
"c:\\screenshot\\googlesearch-webdriverapi.png"));
driver.quit();
}
}
Selenium WebDriver,Running Scripts in a Remote Machine
Selenium is famous for its Cross Browser Testing.With the new changes in Selenium2(Re-implementation of Web driver),running test scripts becomes easier compared to Selenium RC.Selenium web driver does not have any server,but its native API initiates the browser directly.
But this is not suitable for the scenarios where there is a need of running selenium scripts remotely,because we are not running any server.In RC since we are running RC server,we can do that easily.
People of Thought Works came up with a solution for running selenium test remotely.
Here is the procedure for running a selenium test Remotely.
1.Download selenium-server-standalone-2.*.jar Click here to download the jar(If this jar is deprecated please try for a new jar.Just type selenium standalone jar for web driver in Google for new jar).Download the jar file in remote machine.
2.Run the following command java -jar < downloaded jar filepath>in remote machine.
3.Then run the following java code from the machine from which you are going to initiate the remote machine.
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class SeleniumTest {
public static void main(String s[]) throws Exception {
URL url = new URL( "http", "localhost", 4444, "/wd/hub" );
DesiredCapabilities capabilities =DesiredCapabilities.internetExplorer();
System.out.println("1");
capabilities.setJavascriptEnabled(true);
System.out.println("2");
WebDriver driver = new RemoteWebDriver(url,capabilities);
System.out.println("4");
driver.get("http://www.google.com");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshot\\googlesearch-webdriverapi.png"));
driver.quit();
}
}
Change the following statement in your code.
URL url = new URL( "http", "localhost", 4444, "/wd/hub" );
instead of localhost give the remote machine ip address.
Wednesday, August 3, 2011
Who Coined the term "BUG" ?
Every software tester is familiar with the word bug.They Used this word very often.
Who disocovered it?In what application they foound this?
It was very difficult to answer......:)
The term bug was coind by "Grace Hopper" for the first time in 1945.
In 1945, Grace Murray Hopper was working on the Harvard University Mark II Aiken Relay Calculator (a primitive computer).
On the 9th of September, 1945, when the machine was experiencing problems, an investigation showed that there was a moth trapped between the points of Relay #70, in Panel F.
Who disocovered it?In what application they foound this?
It was very difficult to answer......:)
The term bug was coind by "Grace Hopper" for the first time in 1945.
In 1945, Grace Murray Hopper was working on the Harvard University Mark II Aiken Relay Calculator (a primitive computer).
On the 9th of September, 1945, when the machine was experiencing problems, an investigation showed that there was a moth trapped between the points of Relay #70, in Panel F.
Thursday, July 28, 2011
Selenium2.0---Webdriver
Thought Works released their latest version of Selenium(Selenium 2.0).Selenium 2.0 also contains 3 components Selenium IDE,Web Driver and Selenium Grid.
In Selenium2.0 Remote Control is replaced by Web driver.This Web driver is very quick in test execution when compared to Selenium RC.
Major advantages with Web driver when compared to Selenium RC is
1.Selenium RC uses a Proxy through Java Script to launch a browser which usually takes some time,but coming to Web driver it supports some native apis for each web browser(Special api for each browser)so that web browser can be launched quickly using these apis.
2.The API of SeleniumRC is quite complex when compared to Web driver api.
Till now Webdriver supports only Java api.Drivers for all other langauges are still in development stage.
The Webdriver api will be available in the following link
Webdriver API
In Selenium2.0 Remote Control is replaced by Web driver.This Web driver is very quick in test execution when compared to Selenium RC.
Major advantages with Web driver when compared to Selenium RC is
1.Selenium RC uses a Proxy through Java Script to launch a browser which usually takes some time,but coming to Web driver it supports some native apis for each web browser(Special api for each browser)so that web browser can be launched quickly using these apis.
2.The API of SeleniumRC is quite complex when compared to Web driver api.
Till now Webdriver supports only Java api.Drivers for all other langauges are still in development stage.
The Webdriver api will be available in the following link
Webdriver API
Subscribe to:
Posts (Atom)