Skip to main content

Posts

Showing posts with the label Selenium

Prepared database statement and casting

Though database testing is not directly possible from selenium but if you have followed   selenium database testing   video then you know how you can use jdbc to perform database operation from within your java selenium tests.  I came across an interesting problem today when I had to insert value in a database table. On the surface corresponding database insert code looks very easy -  But its execution fails on line 16 with error -  ERROR: column "user_id" is of type integer but expression is of type character varying   Hint: You will need to rewrite or cast the expression.   Position: 163 The problem lies in the following line -  queryBuilder.append("VALUES ('TRUE',?,2,'gift code [BoGJRhmTmImKJlrlFnBlZd+j2dBO3M9a]','50000','1060262','1');"); Herein user_id is represented by "?" and later replaced by real user_id in following line -  updateCreditAccount.setString(1, UserMo...

Installing Selenium Tests Framework

Installing STF - To begin with STF you can clone  seleniumtests  project. It is a sample project which uses STF maven dependency and demonstrate it's feature. If you want to try STF in your own project then please add following dependency to your project - <dependency> <groupId>com.seleniumtests</groupId> <artifactId>seleniumtestsframework</artifactId> <version>4.0</version> </dependency> Please refer maven central repo for  latest version  of STF jar Once cloned and imported, project would look as -  which means that you need to install seleniumtestsframework to your .m2 folder.  You can install seleniumtestsframework using following maven command -  mvn install:install-file -Dfile=C:\Users\testingforum\Desktop\seleniumtestsframework-1.0.jar -DgroupId=com.seleniumtests -DartifactId=seleniumtestsframework -Dversion=1.0 -Dpackaging=jar Here - C:\Users\testing...

5 minutes guides to using Selenium Tests Framework

The best way to learn to write tests using STF is is to use  sample STF project , but in a gist –  • Each test class should extend SeleniumTestPlan Class. SeleniumTestPlan class sets context of test i.e. browser environment etc  /** * Tests valid and invalid login use cases for Test Link * */ public class TestLinkLoginTest extends SeleniumTestPlan • Each page object should extend PageObject class. Refer  Page Object Description  for more on this. PageObject class provides methods for interaction with page like – launching URL, selecting frame, waiting for element availability etc  /** * Defines service for TestLink login page * */ public class TestLinkLoginPage extends PageObject { page object would contain the page element of page. i.e. – Textbox, Dropdown etc –  private static LinkElement seleniumTrainingLink = new LinkElement("Selenium Training LinkElement", By.linkText("Free Selenium Training")); private static TextFieldE...

STF Test Report Snapshots

Here are few selenium test report snapshots from STF - Now is the time to watch    5 minutes guide  to using STF :)

A Dream Died

Not long ago when Dave proposed to have dedicated Selenium site on Stack Exchange . And proposal was badly stuck at 70% and when few us of decided to ask more and more selenium users to commit to it to make it see day of light - After weeks of commit and persuading user we reached 92% commit but then. Well Stack Overflow did not like the ides of having a dedicated selenium site and proposed to merge it with another software testing proposal on Stack Exchange, Which was largely looked down upon at by Selenium Community. Though we were ready for browser automation proposal but merging Selenium proposal with a field like software testing was way to general for us to accept, though we were ready to have it collaborated with browser automation kind of proposal. 

Did you support Selenium Proposal at area51?

There is an effort from SeleniumHQ to migrate selenium user forum from Google Groups to more snazzy and user friendly Stack Exchange . You can find more on this here    So please go ahead and commit to -  http://area51.stackexchange.com/proposals/4693/selenium To do so, you need to login to Stack Exchange site using Google/Yahoo id Now click on Commit button and Fill in a bit of details and yes one more thing is pending yet! You need to confirm your email address only after which your commitment would appear on site.  And do pass it on to other Selenium enthusiasts in your contact list. Since most you have been wondering about advantages of Stackoverflow site over Google Groups, here are the couple of pointers - # As soon as you type in Title for question in Stack Exchange site, it shows related question. This ...

Selenium and Capture Network Traffic

Had heard of it but never tried it my self till today, when a colleague asked about selenium being capable of recording http traffic or not. Did a little Google and found that Selenium 1.0 has api - "captureNetweokTraffic" in DefaultSelenium class, and then needed to know how to use it. To be able to capture network traffic one should start selenium instance as - selenium.start("captureNetworkTraffic=true"); and then launch the application usual way. Once you reach a point after which n/w traffic is to be captured then fire following method - selenium.captureNetworkTraffic("xml"); We can pass - "xml", "plain" or "json" as parameter to this method. Since its return type is String, we can assert presence of any specific request on the response received Though had some trouble while using captureNetworkTraffic, At times I would encounter Internal Server Error from selenium. Or then expected response string will not be av...

Testing auto suggest using Selenium

Happened to work on Auto Suggest feature of late and was to automate it using Selenium. Auto Suggest feature is similar to suggestion list which is displayed when user types in search term in Google or Yahoo search boxes and a suggestion list is displayed for typed in term. Started my experiments with "type()" method of selenium but of no avail. browse through a couple of site and found others have had success using native key press methods. But did not work with me. Then came across combination of using both "type" and "typeKeys" and voila it worked. selenium.type(getPageElement("AutoSuggest", "SearchBox").trim(), ""); selenium.typeKeys(getPageElement("AutoSuggest", "SearchBox").trim(), searchTerm); Though still have some intermittent problems which cause a letter in search term to not be typed in search box in a random fashion, but can live with it for now :-) ~T

XPath and single quotes

I had tough time dealing with XPath and single quote. Though W3C recommends using ' to escape it but I never got it working, let me know if any of you get through. Came across this blog and found that “concat” could be used in this situation. So original XPath expression is – //meta[@name=’DESCRIPTION’][@content=’Tester’s Test’] This is some thing which certainly fails as single quote in “Tester’s” marks it at end of string and then XPath blows up, next trial was – //meta[@name=’DESCRIPTION’][@content=’Tester''s Test’] This does not work despite w3c recommendation! And then I used concat function and split the string as – concat(‘Tester’,”’”,’s Test’) NOTICE that single quote is kept in double quote while other characters are kept in single quotes. So XPath looks as – //meta[@name=’DESCRIPTION’][@content=concat(‘Tester’,”’”,’s Test’)] And this works charm.

Test Automation Recovery Scenarios: how much recovery

This article is not specific to QTP but elaborates a more general problem with functional test automation. I caught the fancy of recovery scenarios when came across such feature in QTP. QTP's motive is to recover from problems of unexpected pop up windows (though concept itself is contradictory and requires you to know object properties of unknown window in advance!) .Though soon realized that it is more of marketing gimmick than of being of much importance to automation it self. Some thing which always puzzled me was how much of such scenarios to use. While under going In house QTP training we were told to even check presence of objects before exercising them. This is to make sure that QTP does not throw any pop up error during test case execution. (at least this is what we were told during training). Later I realized that using QTP properties could be to order QTP do what is intended (though in a limited manner). This idea of checking every object before test freaked me out. I ...

Review of Selenium Book

Not long time ago when I participated in Selenium Documentation and contributed for Selenium Remote Control. I have got one more offer to review an upcoming Selenium book by David Burn. I have never interacted David in person but looks to me he is as passionate about Selenium as I am. I had never imagined that I would get opportunities to review a book in my life, any ways. So far I have reviewed 3 chapters. I must accept that during review I came across Selenium facts which I my self was not aware and I must thank David for this. I hope the book gets finished soon and made available to Open Source community.

Generating Dates in java

This is a small posts which helps in generating custom dates in java. It would be helpful in data generation in Selenium. package com.core; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class DateClass { private static String currentDate; private static String futureDate; public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm"); Calendar cal = new GregorianCalendar(); currentDate = sdf.format(cal.getTime()); // Current date System.out.println(cal.getTime()); // Formatted current date System.out.println("Formatted Date is: " +currentDate); cal.add(Calendar.DATE, 1); futureDate = sdf.format(cal.getTime()); // Formatted future Date System.out.println("Future Date is: " +futureDate); } }

Testing XPath in Firebug

Given the lack of testing hooks in web applications, many a times Selenium Users use XPath to work on UI Objects. So far I used to use Selenium IDE to test XPath in Firefox. I read a blog post here and got to know that Firebug itself can be used to test XPath. This is accomplished using $x function in Firefox. Consider that highlighted text box does not have a constant identifier hence following XPath is to be used > $x("//input[@name='search']") Write this XPath on Console of Firebug and hit enter - Keep mouse pointer on 'input' in console and it would highlight the text box in page. Using Firebug Lite Firebug can be used for other browsers as well and in turn to test XPath on other browsers.......

Selenium Function Library

Poornima and I built collection of java Classes for selenium which provide capabilities which are not built in Selenium like - HTML Table Parsing, Custom Verification, Logging to name a few. This project is been existent from some time now, though I never had chance to write up on this. Whole project is available under "Repository" section of Veda for "Testing Competency" project and can be opened using java IDE like Eclipe. Best way to get acquainted with this API is to generate java doc your self which is no more than child's play. Make sure you have java 1.5 or higher and ANT 1.7.0 Configure System variable for Java and ANT, once having done this u should be able to see version of java and ant on your console on doing - "java-version" and "ant -verison" On Console navigate to path where Sel Library is check out, it turns out to be following for me - "D:\SelFunctionLibrary\SeleniumFunctionLibrary>" Execute following ANT ...

HTML Parsing and Selenium

HTML parsing is always been a burning requirement with selenium. Though Selenium doesn’t have built in API which could do HTML parsing, given its high integrability it could be integrated with HTMP parser to achieve the same. I have experimented on HTML parsing using Jericho which is java library. To begin HTML parsing the only demand Jericho makes is about HTML Source and this could be obtained using Selenium API - getHtmlSource(). Herein I have listed functions which I have developed using Jericho - Count number of tables on a page – // Get Source object for HTML Tables. Source source = new Source(selenium.getHtmlSource()); List table = source.getAllElements(HTMLElementName.TABLE); Reporter.log("Number of Tables are: " +table.size()); ***Reporter is TestNG API*** Retrieve Table Data- // Retrieve table data from a specific table.Source tableSource = new Source(table.get(3).toString()); Reporter.log("Table data is:" +HTMLTableParser.getTableData(tableS...

Retrieving dynanic HTML Objects from selenium

We often come across situations of dynamic html objects where in HTML id/name of a page is not constant and some time we don't even get to have any constant part if HTML identifier. Of late I came across a page which had lots of check boxes but no part oh HTML id/name was constant. To over come this we created custom functions for selenium using js evaluation capabilities of selenium. Function objectives are: ****** Retrieves all dropdown objects in a web page ****** Retrieves all multiline text box objects in a web page ****** Retrieves all radio button objects in a web page ****** Retrieves all check box objects in a web page ****** Retrieves all text box objects in a web page Depending on the availability of HTML id or name these functions would retrieve either HTML id or name. These methods are as following -

How selenium recorder compares with other tools?

I had chance to work on QTP and to sneak in to Test Complete in my Organization. I am bit depressed as to how irrationally QTP and Test Complete record web application and how much script one should tweak manually to make it compact. Let me cite example of Google Search for this. A selenium test for Google Search would be like this - selenium.open("http://www.google.com/"); selenium.type("q", "I love My Company"); selenium.click("btnG"); This certainly gives impression of app being opened, some thing being typed (though "q" might not be very clear here) and some button being clicked (again "bthG" is not very clear here) Same recorded test in QTP be as following - Browser("Google").Page("Google").WebEdit("q").Set "I Love My Company" Browser("Google").Page("Google").WebButton("google search").Click Google With Browser and Page objects embedded ev...

Testing HTML object using DOM and selenium

DOM is w3c standard for navigating through the objects of a structured doc, Same can be used for exercising HTML/XML docs. In HTML, each element is referred as an object hence text box, dropdown, radio button etc are objects. These objects have properties (like max length in case of text box etc) and methods. Herein properties of objects can be collected in selenium through evaluation of java script and then these can be compared against expected values. For example one can collect max length and size properties of text box by evaluating java script through getEval function as following - selenium.getEval("var property = new Array(); property[0] = window.document.getElementsByName('empNumber')[0].maxLength;" + "property[1] = window.document.getElementsByName('empNumber')[0].size; property.toString();"); /**** I have explained evaluation of js in issue - 9211 ****/ Now individual properties can be collected in an string array as following - String[] T...

Execute java script from selenium

getEval method can be used to evaluate java script from selenium. Remember to use window object in case of dom expressions as by default selenium window is referred and not the test window. Hence a sample code will look as following - selenium.getEval("window.document.images.length;"); This will return total number of images in a web page. Same result can be retrieved using only "document.images.length;" string IF selenium is run in proxy injection mode. (As selenium runner will not appear in the test window). BUT To be on safer side irrespective of mode selenium is run always use 'window' object of java script. If evaluated expression is to return multiple values then use it as following - This will return all the image links available on a page. This can be collected in a string and individual links can be found by using split method. Now to execute java script using Selenium IDE. lets type a random number on a text box -     type   ...