Total Pageviews

Monday, December 19, 2011

Different ways to verify pop-up/Window using selenium


SelectWindow:

If the window name/title is null, then we can focus the window/pop-up as below mentioned manner:


For this we can use, selectWindow | windowName command and to go back to main window from other window, we can use  selectWindow | null


Arguments:
  • by windowid - the java Script window id of the window to select. - Selects pop-up window id using window locator; Once a window selected, all the commands will execute on the pop-up window until main window selected.  To select the main window, use null as a target.
We can select the window by providing different objects:
  • by title, by internal java script "name" or by java script "variable".
    • title= MyWindow: This text appears in the title bar. some times two windows can have the same title, in that scenario, this locator will just pick one. 
      •  name=myWindow: Finds the window using its internal JavaScript "name" property. This is the second parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which Selenium intercepts). 

      • var=variableName: Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using "var=foo".


selectPopup:

If it is a popup then do selectPopUp | windowId and then to go back to the main window do selectWindow | null

selectPopUp(windowID) Arguments:

    * windowID - an identifier for the popup window, which can take on a number of different meanings

Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).

    * If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play.

    * Otherwise, the window will be looked up considering windowID as the following in order: 1) the "name" of the window, as specified to window.open(); 2) a javascript variable which is a reference to a window; and 3) the title of the window. This is the same ordered lookup performed by selectWindow . 

Sunday, December 18, 2011

Verify the color of an object using selenium


The HTML code is
//<input name="input" class="form-text required error" id="edit-input" type="text" size="20" maxLength="255"/>

//<input name="op" class="form-submit" id="edit-submit-1" type="submit" value="Submit"/>

The Code example to check the above behavior is
@Test
  public void iscolorchanged() {
        org.openqa.selenium.ie.InternetExplorerDriver driver = new org.openqa.selenium.ie.InternetExplorerDriver();
        driver.get("the url to test");
        WebElement submitbutton = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>(){
            @Override
            public WebElement apply(WebDriver d) {
                  return d.findElement(By.xpath("//*[@id='edit-submit-1' and @name='op']"));
            }}); 
        submitbutton.submit();
        WebElement inputbox = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>(){
            @Override
            public WebElement apply(WebDriver d) {
                  return d.findElement(By.xpath("//*[@id='edit-input'and @class='form-text required error']"));
            }}); 
        Boolean colorchanged;
        String color= inputbox.getCssValue("border-color");
        if(color.equals("#ff0000"))
                    {
                          colorchanged=true;
                    }
                    else
                    {
                          colorchanged=false;
                    }
                   
        System.out.println( colorchanged);
       
        }

Gathered from Net

Monday, December 12, 2011

Selenium Locaters - Hand Book

Hi all,

Here I added a new hand book which I got it from Net. This is very useful for selenium testers to construct Objects.

You can download this from here

Selenium Locaters - HandBook

Wednesday, November 30, 2011

Free Load testing Tools webApplications


Pylot - Open Source Load Testing Tool
Pylot is an open source tool which runs HTTP load tests for testing performance and scalability of web services.
It generates concurrent load (HTTP Requests), verifies server responses, and produces reports with metrics. Tests suites are executed and monitored from a GUI or shell/console.

Tsung

Tsung
Tsung can be used to stress almost any kind of server including:
  • HTTP
  • WebDAV
  • SOAP
  • PostgreSQL, MySQL
  • LDAP
  • Jabber/XMPP servers.
Several IP addresses can be used on a single machine using the underlying OS IP Aliasing& HTTP reports are generated during the tests.

Apache JMeter

Apache JMeter
Apache JMeter may be used to test performance both on static and dynamic resources. Besides HTTP, it can connect to databases, POP3 & more.

Siege

Siege - Load Testing Tool
Siege is an http regression testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet.
It supports basic authentication, cookies, HTTP and HTTPS protocols. It allows the user hit a web server with a configurable number of concurrent simulated users.
Siege was written on GNU/Linux and has been successfully ported to AIX, BSD, HP-UX and Solaris.

The Grinder

Java Load Testing
The Grinder is a Java load testing framework that makes it easy to run a distributed test using many load injector machines.
Tests are written in Jython scripting language. It has an automatic management of client connections and cookies.

Integration Jmeter with Selenium


1) Write the selenium  junit test code for functionality  of your application.   Code should be error free.

2) After the test case is successfully run, we will get a .class file in bin folder.

3) Make jar of .class file and .java files. This can be done by doing the  following steps in Eclipse :
Go to File --> Export --> java --> Jars--> next --> browse location -->  Finish   

4) Copy and Paste that jar file under jmeter installation path /jakarta-jmeter-< version >/ lib/junit

5) Copy and Paste selenium-java-client-driver.jar and selenium-server.jar files under jmeter installation path /jakarta-jmeter-<version>/lib

6) Start jmeter

7) Create a test plan  in JMeter by following below steps . 
Click on test plan --> add thread groups and Go to Thread group--> Add --> Sampler --> Junit request

8) Under class name, we can check our package .class name. Select that particular .class file. 

9) Run the test plan. Now we can observe that selenium junit test cases will be running with multiple number of users at a time

Thursday, August 18, 2011

Validation of a tool tip

To validate the tooltipof below mentioned site:

https://www.google.com/adsense/g-app-single-1?hl=en&sourceid=aso&subid=ww-en-et-ads&medium=link

selenium.mouseOver(""//img[contains(@id,'tooltipImage')])
Thread.sleep(1000);
selenium.mouseOver("//div[contains(@class,tooltipPopup)]")
Thread.sleep(1000);
selenium.getText("//div[contains(@class,tooltipPopup)]/meta/a")

Launching the Selenium RC - Window Service.

Lunching the selenium RC as window service by following manner:

Here are the steps:
  1. Install the latest Java runtime if you don't have it installed already
  2. Install the Selenium server (e.g. C:\Selenium\selenium-server-1.0.1
  3. Download srvany.exe and instsrv.exe (these are part of the Microsoft Windows Resource Kit - you will need to download the correct version for your OS) and copy these files to a location on your server (e.g. C:\reskit)
  4. Browse to this folder, and type: instsrv "Selenium RC" "C:\reskit\srvany.exe" - this will create the windows service named "Selenium RC", which will now be installed as a Windows service, although it won't start up yet
  5. Open up regedit, and browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Selenium RC
  6. Right-click "Selenium RC" in the tree, and click New - Key, and add a key called "Parameters"
  7. Open Parameters, and create a new string value called "Application"
  8. Add the following to the data value for the new string value: "C:\Program Files (x86)\Java\jre6\bin\java.exe" -jar "C:\Selenium\selenium-server-1.0.1\selenium-server.jar", substituting paths to the java exe and the selenium server jar file where appropriate
  9. Load up the windows services console (services.msc) and start the service





Wednesday, August 17, 2011

Launching Broswer using different methods

we can launch the browser by following ways:
  • Using default selenium object.
  • Using webdriver object.
  • Using HTTPCommandProcesser object.
  • Using WebDriver backed Selenium object.

By default selenium object:

    browser=new DefaultSelenium("localhost",4444, "firefox","http://www.google.com");
    browser.start();
    browser.windowMaximize();
    browser.open("http://www.google.com");

By Webdriver Object:
  
    WebDriver browser1;
    browser1=new FirefoxDriver();
    browser1.get("http://www.google.com");

By HTTPCommandProcesser object:

    HttpCommandProcessor browser2;
    browser2= new HttpCommandProcessor("localhost", 4444, "*firefox", "http://www.google.com");
    browser2.start();
    String[] url={"http://www.google.com"};
    browser2.doCommand("open", url);
  
By WebDriver backed Selenium object:
  
    browser1=new FirefoxDriver();
    browser=new WebDriverBackedSelenium(browser1,"http://www.google.com");
    browser.open("http://www.google.com");
    browser.windowMaximize();








How to handle ssl certificate error in selenium rc

Hi all,
when your tests redirect to an HTTPS URL on the same host, where your SSL certificate is self-signed, things go wrong. As Selenium effectively runs Firefox with a new profile every time, you potentially lose any certificate exceptions you might accept.

We have a technique to avoid this problem:
  - create a custom profile;
  - run Firefox using that profile;
  - browse to the HTTPS URL and accept the exception into that profile;
  - close the profile.

Steps to create a Firefox profile:
1. Close down any running Firefox instances.
2. Start Firefox (the one you're going to run your tests with) with the profile manager: firefox –ProfileManager using command prompt.
3. Create a new profile. You'll be prompted to choose a directory for the profile. Put it somewhere inside the project where you're writing the tests.
4. Select the profile and run Firefox using it.
5. Browse to the HTTPS URL (with self-signed certificate) you're going to be testing against.
6. Accept the self-signed certificate when prompted. This creates an exception for it in the profile.
7. Close the browser.
8. Go to the Firefox profile directory.
9. When you run your Selenium server, pass a -firefoxProfileTemplate /path/to/profile/dir argument to it. This tells Selenium to use your partial profile (with certificate exceptions) as a basis for minting its new profile. So you get the certificate exceptions, but without any of the other clutter you would get if you used a whole profile.


command for using the firefox profile template in selenium server.

java -jar selenium-server.jar -firefoxProfileTemplate /path/to/profile \
-htmlSuite “*chrome firefox-bin” “http://host.com” “testSuite.html” “seleniumResults.html”

Monday, May 23, 2011

Way to Get XPATH in IE

Are you stuck with an application that only works in IE?
Do you want the XPATH of an element that can be seen only IE? Unable to replicate the scenario in firefox. There are many firefox addons like xpather, xpath-checker and firebug that will give you the xpath of an element in a second. But sadly there is no addon or tool avaialable that will do this for IE. For most cases you can get the xpath of the elements that fall in your script using the above tools in firefox and tweak them a little (if required) to make them work in IE. But if you are testing an application that will work only in IE or the specific scenario or page that has this element will open-up/play-out only in IE then you cannot use any of the above mentione tools to find the XPATH.
Well the only thing that works in this case is the Bookmarklets that were coded just for this purpose. Bookmarklets are JavaScript code that you will add in IE as bookmarks and later use to get the XPATH of the element you desire. Using these you can get the XPATH as easily as you get using xpather or any other firefox addon.

STEPS TO INSTAL BOOKMARKLETS
1)Open IE
2)Type about:blank in the address bar and hit enter
3)From Favorites main menu select--->Add favorites
4) In the Add a favorite popup window enter name GetXPATH1.
5)Click add button in the add a favorite popup window.
6)Open the Favorites menu and right click the newly added favorite and select properties option.
7)GetXPATH1 Properties will open up. Select the web Document Tab.
8)Enter the following in the URL field.

javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(node.id!=''){nodeExpr+="[@id='"+node.id+"']";return "/"+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='['+rank+']';}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]';break;}ns=ns.nextSibling;}}return nodeExpr;}

9)Click Ok. Click YES on the popup alert.
10)Add another favorite by following steps 3 to 5, Name this favorite GetXPATH2 (step4)
11)Repeat steps 6 and 7 for GetXPATH2 that you just created.
12)Enter the following in the URL field for GetXPATH2

javascript:function o__o(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1)break;}currentNode=currentNode.parentNode;}var xpath="/"+path.reverse().join('/');clipboardData.setData("Text", xpath);}o__o();

13)Repeat Step 9.

You are all done!!

Now to get the XPATH of elements just select the element with your mouse. This would involve clicking the left mouse button just before the element (link, button, image, checkbox, text etc) begins and dragging it till the element ends. Once you do this first select the favorite GetXPATH1 from the favorites menu and then select the second favorite GetXPATH2. At his point you will get a confirmation, hit allow access button. Now open up a notepad file, right click and select paste option. This will give you the XPATH of the element you seek.


*I got this bookmarklets from some other site but can't remember which one. Credit goes to the guy who created these JS.

Monday, April 18, 2011

Selenium IDE on Firefox 4

Just saw in Samit Badle Post that Selenium IDE v1.0.11 is getting ready for release .It will be released as soon as possible . See the post in this link for more details

http://blog.reallysimplethoughts.com/2011/04/07/selenium-ide-on-firefox-4-is-available-for-testing-now/

Until then use this Workaround to use Selenium on Firefox4

1. Type about:config in your browser address bar
2. Agree to the warning message
3. Right click inside the browser and the choose New -> Boolean
4. Set the preference name to "extensions.checkCompatibility.4.0"
5. Set the value to False
6. Restart Firefox

Selenium IDE should work now ..With due respect the above workaround was given by Mark Collins in Selenium User Groups

Difference between seleniumserver.boot() and seleniumserver.start()

when we use .boot() your user-extensions.js is invoked too, which is not the case when you use .start() .
Seleniumserver.boot internally calls Selenium.server ..So using boot and start in same code means like trying to start the server twice .

Why Name Selenium

I was wondering all this time why Selenium Testing Tool name clashes with chemical element "Selenium" having atomic number 34 . Seems i got an answer now . Jason Huggins started selenium in 2004 in order to find an alternative to QTP and selenium mineral supplements serve as a cure for mercury poisoning ..Hence he choose the name Selenium .

Dont know whether it is good or bad , but Selenium Testing tool dominates Selenium element in google search results in the top ten (7 : 3) .


Wednesday, March 16, 2011

About Selenium


Selenium is an open source tool for web application testing.This tool is primarily developed in JavaScript and browser technologies and hence supports all the major browsers on all platforms.
Selenium provides a test domain specific language (DSL) to write tests in a number of popular programming languages like Java, Ruby, Perl, Python, PHP, C#, HTML.
Selenium was originally developed by Jason Huggins, who was later joined by other programmers and testers at Thought works.
The browsers that are supported by Selenium are Internet Explorer, Mozilla Firefox, Google Chrome, Opera, and Safari.
Selenium runs on Windows, Linux and Macintosh operating systems.
Selenium enables Browser Compatibility Testing.
Selenium enables System Functional Testing.

How Selenium Works
Selenium uses JavaScript and Iframes to embed a test automation engine in your browser.
Selenium Core runs the test and interrogates the DOM.
Selenium RC server and Core communicate via AJAX.

Supported Environments:
The environments supported by Selenium are as below:

Browsers
Browser
Selenium IDE
Selenium Remote Control
Selenium Core
Firefox 3
Record and playback tests
Start browser, run tests
Run tests
Firefox 2
Record and playback tests
Start browser, run tests
Run tests
IE 8
not supported
Start browser, run tests
Run tests
IE 7
not supported
Start browser, run tests
Run tests
Safari 3
not supported
Start browser, run tests
Run tests
Safari 2
not supported
Start browser, run tests
Run tests
Opera 9
not supported
Start browser, run tests
Run tests
Opera 8
not supported
Start browser, run tests
Run tests
Others
not supported
Partial support possible*
Run tests**

Operating Systems
OS
Selenium IDE
Selenium Remote Control
Selenium Core
Windows
Works in Firefox 2+
Start browser, run tests
Run tests
OS X
Works in Firefox 2+
Start browser, run tests
Run tests
Linux
Works in Firefox 2+
Start browser, run tests
Run tests
Solaris
Works in Firefox 2+
Start browser, run tests
Run tests
Others
Should work in Firefox 2+
Start browser, run tests*
Run tests**



Wednesday, March 9, 2011

How to generate Test Result Report using Ant from Java eclipse

Reporting is the most important thing in testing.
Below mentioned steps are to  configure and generate the test result from java eclipse using Ant.

Generating the ANT build:
Right click on the project and select Export --> Ant Buildfiles.-->Next-->Select the project-->Finish.
Configuring jar:
Select Windows menu-->Preference -->Global Entries -->Add External JARs-->Select the folder where the eclipse is installed. eclipse -->Plugin -->Currently its located in "org.junit_4.8.1.v4_8_1_v20100427-1100"-->"junit.jar"-->OK.
Run the Ant Build:
right click on build.xml go to run as- external tools confirgurations ---targets tab and select your test suites and junitreport.   then right click on build.xml and run as antbuild file...