ISTQB Certified Software Test Engineer

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.

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

Wednesday, July 27, 2011

Mock Objects for quick Unit Testing

For large or smalle Code of Applications it is Programmers job to test their code.Unit Testing one of the levels in Software Testing is purely for the developers.They have to write unit tests and they have to examine(test) their code.

A good unit test case is a small piece of code(mostly written in a single method)which is for testing specific functionality.In Large,complex well designed systems different objects have to work together to accomplish a particular task.
For example in order to write a simple test case to verify Login functionality user name and password has to be taken from database and using these as inputs test case has to be executed.

So if we are using database we have to create many objects(eg:Objects for Prepared statements,Result Set,DB Connection etc..).It is a complicated task to create some 'N' objects for testing simple unit test case.Creating these 'N' doesn't make our unit test to be completed in quick time.

Mock Objects are the Objects which Pretended to be as Real Objects makes this process easier.A mock object is a replacement for a real object that we create for the express purpose of testing. Mock objects were championed by Tim Mackinnon, Steve Freeman, and Philip Craig


There are Many Frameworks for effective usage of mock objectes in our unit tests like JMock,Mockito,EasyMock etc..

Tuesday, July 26, 2011

FITNESSE A USER ACCEPTANCE TESTING TOOL


What is User Acceptance Testing?

User Acceptance Testing is often the final step before rolling out the application. Usually the end users who will be using the applications test the application before ‘accepting’ the application. This type of testing gives the end users the confidence that the application being delivered to them meets their requirements.
User Acceptance Testing – How to Test?
The user acceptance testing is usually a black box type of testing. In other words, the focus is on the functionality and the usability of the application rather than the technical aspects. It is generally assumed that the application would have already undergone Unit, Integration and System Level Testing.
However, it is useful if the User acceptance Testing is carried out in an environment that closely resembles the real world or production environment.
The steps taken for User Acceptance Testing typically involve one or more of the following:
.......1) User Acceptance Test (UAT) Planning
.......2) Designing UA Test Cases
.......3) Selecting a Team that would execute the (UAT) Test Cases
.......4) Executing Test Cases
.......5) Documenting the Defects found during UAT
.......6) Resolving the issues/Bug Fixing
.......7) Sign Off
What is Fitnesse?
FitNesse is a web server, a wiki, and an automated testing tool for software. It is based on Framework for Integrated Test (FIT). FitNesse is designed to support acceptance testing. Fitnesse allows users of a developed system to enter specially formatted input. This input is interpreted and tests are created automatically. These tests are then executed by the system and output is returned back to the user. The advantage of this approach is very fast feedback from users. The developer of the system to be tested needs to provide some support (classes named "fixtures").

Monday, June 27, 2011

IE Script Error while running Selenium RC


Today while running Selenium RC in IE8 in windows 7 i have got this error.I googled to find a solution for the above error and atlast i was passed.
1.Open command prompt and run it in adminstartor mode.
Right click on CMD and click on Run as Administrator




2.Run Selenium server jar and continue running your tests.

Script error will be fixed and we will get a result

Friday, January 7, 2011

CSS Conditional comments

Cascading style sheets(CSS) conditional comments are used to fix browser issues.They work only for windows ie.Other browsers treat these lines of code as commnets except ie due to their syntax.Here is the example
<!--
<!--[if IE 6]>
.header{
width:600px;
}<![endif]-->
-->

The above piece of code should be added in head section of the html file.
For example if we set the width to 700px in ie6 the width will be reset to 600px due to this conditional comments.
So we can solve ie cross browser issues using this by writing styles individually for each ie.
U can have clear idea on this conditional comments with this example
<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
</p>


Copy the above code and save in html file and run the html file in different ie versions,so that u can clearly understand coditional comments