This blog comprises of learning to get started with Open source automation tools. Mentions best practices of Agile,Xtreme Programming Selenium In nutshell.
Favourite Quote
Wednesday, November 17, 2010
ProxyInjection Mode
*pi(browsername);
2.How to avoid using waitForpageload() ,wait(),pause(),thread.sleep()?
Add selenium.setSpeed(Constants.DEFAULT_TIMEOUT); at the start of the script.
3.How to check for dynamic ids in the object string using xpath
for example if dynamic ids have the format text-12345
where 12345 is a dynamic number you could use the following
XPath: //input[starts-with(@id, 'text-')]
4.How to Capture selenium server side logs if you don't start the server through code ?
java -jar selenium-server.jar -log selenium.log
5.How to Capture Browserside logs?
java -jar selenium-server.jar -log browserSideLog
6.How to use contains function in xpath ?
"//a[contains(text(),'Add New')]"
If there are multiple Add New on page its better to nail down to the one we are looking to click with index subscript.
//a[contains(text(),'Posts')]/following::a[contains(text(),'Add New')][1]
So we are using xpath axis which is following & an index[1]
Axis are used to work with node sets
How to Capture Network Traffic using Selenium
public class Epc extends SeleneseTestCase
{
public static SeleniumServer selServer;
public static DefaultSelenium selenium;
final String URL = "http://10.10.7.48:38080/";
int port = Constants.PORT;
String browser = Constants.BROWSER;
public void setUp() throws Exception
{
if(selServer == null)
{
try
{
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.trustAllSSLCertificates();
selServer = new SeleniumServer(rc);
selServer.start();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
public void testWebservices() throws Exception
{
selenium = new DefaultSelenium("localhost",Constants.PORT,Constants.BROWSER,URL);
selenium.start("captureNetworkTraffic=true");
selenium.open("/epc-client");
String trafficOutput = selenium.captureNetworkTraffic("plain");
System.out.println("\nNetwork Traffic captured in plain format !!!!"+trafficOutput);
pause(Constants.MAX_WAIT_TIME_MS);
selenium.windowFocus();
selenium.windowMaximize();
selenium.useXpathLibrary("javascript-xpath");
pause(Constants.MAX_WAIT_TIME_MS);
selenium.click("link=Search UPRN by Address Web Service");
}
}
public void tearDown()
{
selenium.stop();
selServer.stop();
}
}
Wednesday, November 10, 2010
DataDriven Testing using Selenium - java
public void login()
{
String uName = username;
String pWord = password;
try
{
FileInputStream fi = new FileInputStream ("C:\\Selenium\\datainput\\webservices.xls");
Workbook wbk = Workbook.getWorkbook(fi);
Sheet sht = wbk.getSheet("Credentials");
for(int rowCount=1;rowCount<=sht.getRows();rowCount++)
{
uName = sht.getCell(1,rowCount).getContents();
pWord = sht.getCell(2, rowCount).getContents();
objSelenium.type("xpath=//input[@id='j_username']", uName);
selenium.wait(Constants.MAX_WAIT_TIME_MS);
objSelenium.type("xpath=//input[@id='j_password']", pWord);
selenium.wait(Constants.MAX_WAIT_TIME_MS);
}
}catch(Exception e)
{
e.printStackTrace();
}
}
Generating HTML reports at granularity
Using the LoggingSelenium Interface.
1.Must have Selenium-client.jar for java
2.Junit4.jar
3.Commons-lang.jar
4.loggingselenium.jar
Include all the above jars in your classpath.
package com.est.org;
// import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertEquals;
// import static com.unitedinternet.portal.selenium.utils.logging.LoggingAssert.assertTrue;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.ParseException;
import jxl.Sheet;
import jxl.Workbook;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.HtmlResultFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingCommandProcessor;
import com.unitedinternet.portal.selenium.utils.logging.LoggingDefaultSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingResultsFormatter;
import com.unitedinternet.portal.selenium.utils.logging.LoggingSelenium;
import com.unitedinternet.portal.selenium.utils.logging.LoggingUtils;
import org.openqa.selenium.server.*;
public class Loggingselenium
{
protected LoggingSelenium selenium;
private BufferedWriter loggingWriter;
private static final String RESULT_FILE_ENCODING = "UTF-8";
private static final String DEFAULT_TIMEOUT = "30000";
private static final String OPENQA_URL = "http://192.168.9.104:8080/";
private static final String SCREENSHOT_PATH = "screenshots";
private final String RESULTS_BASE_PATH = "C:/" + File.separator+ "loggingResults" + System.currentTimeMillis();
private String resultsPath = new File(RESULTS_BASE_PATH).getAbsolutePath();
private String screenshotsResultsPath = new File(RESULTS_BASE_PATH+ File.separator + SCREENSHOT_PATH).getAbsolutePath();
private SeleniumServer selServer;
@Before
public void setUp() {
if (!new File(screenshotsResultsPath).exists()) {
new File(screenshotsResultsPath).mkdirs();
}
final String resultHtmlFileName = resultsPath + File.separator+ "sampleResultSuccess.html";
loggingWriter = LoggingUtils.createWriter(resultHtmlFileName,Loggingselenium.RESULT_FILE_ENCODING, true);
LoggingResultsFormatter htmlFormatter = new HtmlResultFormatter(loggingWriter,Loggingselenium.RESULT_FILE_ENCODING);
htmlFormatter.setScreenShotBaseUri(Loggingselenium.SCREENSHOT_PATH+ "/");
htmlFormatter.setAutomaticScreenshotPath(screenshotsResultsPath);
if(selServer == null)
{
try
{
SeleniumServer selServer = new SeleniumServer();
selServer.start();
}catch(Exception e){}
}
LoggingCommandProcessor myProcessor = new LoggingCommandProcessor(new HttpCommandProcessor("localhost", 4444, "*firefox",OPENQA_URL), htmlFormatter);
myProcessor.setExcludedCommands(new String[]{});
selenium = new LoggingDefaultSelenium(myProcessor);
selenium.start();
}
@After
public void tearDown() {
selenium.stop();
try {
if (null != loggingWriter) {
loggingWriter.close();
}
} catch (IOException e) {}
}
@Test
public void loggingSelenium() throws InterruptedException,ParseException
{
selenium.setContext("loggingSelenium()");
selenium.open("/epc-client");
selenium.windowFocus();
selenium.windowMaximize();
selenium.captureScreenshot(screenshotsResultsPath + File.separator+ "openQaHomePage_" + LoggingUtils.timeStampForFileName()+ ".png");
try {
selenium.click("link=Search UPRN by Address Web Service");
selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
selenium.click("//input[@type='radio'][6]");
FileInputStream fi = new FileInputStream("C:\\Selenium\\datainput\\webservices.xls");
Workbook wBk = Workbook.getWorkbook(fi);
Sheet sht = wBk.getSheet("webService");
selenium.type("request",sht.getCell(3,0).getContents());
selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
selenium.wait(30000);
selenium.click("//input[@name='Submit' and @value='submit']");
selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
String textArea = selenium.getValue("//textarea[@name='header']");
if(textArea.contains("null"))
{
System.out.println("\n Invalid request XML submitted!!!!");
}
} catch (Exception e) {}
}
}
Friday, October 22, 2010
Get All link Names ... using xpath
package com.est.org;
import org.openqa.selenium.server.*;
import com.thoughtworks.selenium.*;
import com.thoughtworks.selenium.DefaultSelenium;
public class epcClient extends SeleneseTestCase
{
public static SeleniumServer selServer;
public static DefaultSelenium selenium = null;
final String browser = "*firefox";
final int MAX_TIME_TO_WAIT = 3000;
final int PORT = 4444;
final String URL = "http://abc.com/";
public void setUp() throws Exception
{
if(selServer == null)
{
try
{
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.trustAllSSLCertificates();
selServer = new SeleniumServer(rc);
selServer.start();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
public void testWebservices()
{
selenium = new DefaultSelenium("localhost",PORT,browser,URL);
selenium.start();
selenium.open("/open");
pause(MAX_TIME_TO_WAIT);
selenium.windowFocus();
selenium.windowMaximize();
pause(MAX_TIME_TO_WAIT);
int count = selenium.getXpathCount("//a").intValue();
for(int i=1;i<=count;i++)
{
//Iterate the received links through getText
String getlink = selenium.getText("xpath=(//a)["+i+"]");
System.out.println("\n Here's the link that you have got !!! "+getlink);
selenium.click("link="+getlink);
pause(MAX_TIME_TO_WAIT);
selenium.click("//input[@type='radio'][5]");
pause(MAX_TIME_TO_WAIT);
selenium.click("//input[@name='Submit' and @value='submit']");
selenium.waitForPageToLoad("30000");
assertEquals(selenium.getTitle(),true);
selenium.open("/open");
pause(MAX_TIME_TO_WAIT);
selenium.windowFocus();
selenium.windowMaximize();
}
}
public void tearDown()
{
selenium.stop();
selServer.stop();
}
}
Friday, October 15, 2010
Continue ... Scrum
Starting Scrum
The first step in Scrum is for the Product Owner to articulate the product vision. Eventually,this evolves into a refined and prioritized list of features called the Product Backlog.
The subset of the Product Backlog that is intended for the current release is known as the Release Backlog, and in general, this portion is the primary focus of the Product Owner.
Scrum does not define techniques for expressing or prioritizing items in the Product Backlog and it does not define an estimation technique. A common technique is to estimate in terms of relative size (factoring in effort, complexity, and uncertainty) using a unit of “story points”
or simply “points”.
The Product Backlog items for the upcoming next several Sprints should be small and fine-grained enough that they are understood by the Team, enabling commitments made in the Sprint Planning meeting to be meaningful; this is called an “actionable” size.
Popular Agile Method - Scrum
Scrum is an iterative, incremental framework for projects and product or application
development. It structures development in cycles of work called Sprints. These iterations are no more than one month each, and take place one after the other without pause. The Sprints are timeboxed – they end on a specific date whether the work has been completed or not, and
are never extended.
Scrum Roles
In Scrum, there are three roles:
- The Product Owner
- The Team
- The ScrumMaster.
Together these are known as The Scrum Team.
The Product Owner is responsible :
For maximizing return on investment (ROI) by identifying product features, translating these into a prioritized list.
Deciding which should be at the top of the list for the next Sprint, and continually re-prioritizing and refining the list.
The Product Owner has profit and loss responsibility for the product, assuming it is a commercial product.
In case of an internal application, the Product Owner is not responsible for ROI in the sense of a commercial product (that will generate revenue), but they are still responsible for maximizing ROI in the sense of choosing – each Sprint – the highest-business-value lowest-cost items.
The Team builds the product that the Product Owner indicates
The Team in Scrum is “cross-functional” – it includes all the expertise necessary
to deliver the potentially shippable product each Sprint – and it is “self-organizing” (selfmanaging).
With a very high degree of autonomy and accountability. The Team decides what to
commit to, and how best to accomplish that commitment
The Team in Scrum is seven plus or minus two people, and for a software product the Team might include people with skills in analysis, development, testing, interface design, database design, architecture, documentation, and so on
The ScrumMaster helps the product group learn and apply Scrum to achieve business value.
The ScrumMaster does whatever is in their power to help the Team and Product Owner be
successful.
The ScrumMaster is not the manager of the Team or a project manager; instead, the
ScrumMaster serves the Team, protects them from outside interference, and educates and guides the Product Owner and the Team in the skillful use of Scrum.
In addition to these three roles, there are other contributors to the success of the product, including functional managers (for example, an engineering manager).
While their role changes in Scrum, they remain valuable. For example:
• they support the Team by respecting the rules and spirit of Scrum
• they help remove impediments that the Team and Product Owner identify
• they make their expertise and experience available
Friday, September 3, 2010
Selenium Coupled with Eclipse and Java
Wednesday, June 16, 2010
Agile Testing
The Word Agile means "Moving Quickly" and this explains the whole concept of Agile Testing. Testers have to adapt to rapid deployment cycles and changes in testing patterns.
Agile testing involves testing from the customer perspective as early as possible, testing early and often as code becomes available and stable enough from module/unit level testing.
Since working increments of the software are released often in agile software development, there is also a need to test often. This is commonly done by using automated acceptance testing to minimize the amount of manual labor involved. Undertaking only manual testing in agile development may result in either buggy software or slipping schedules, as it may not be possible to test the entire build manually before each release.
In Agile Testing, testers are no longer a form of Quality Police. Testing moves the project forward leading to new strategy called Test Driven Development.
Testers provide information, feedback and suggestions rather than being last phase of defense.
Testing is no more a phase; it integrates closely with Development.
Continuous testing is the only way to ensure continuous progress.
Reduce feedback loops, Manual regression tests take longer to execute and, because a resource must be available, may not begin immediately.
Feedback time can increase to days or weeks. Manual testing, particularly manual exploratory testing, is still important.
However, Agile teams typically find that the fast feedback afforded by automated regression is a key to detecting problems quickly, thus reducing risk and rework.
Keep the code clean. Buggy software is hard to test, harder to modify and slows everything down. Keep the code clean and help fix the bugs fast.
Lightweight Documentation Instead of writing verbose, comprehensive test documentation.
Agile testers:
• Use reusable checklists to suggest tests
• Focus on the essence of the test rather than the incidental details
• Use lightweight documentation styles/tools
• Capturing test ideas in charters for Exploratory Testing
• Leverage documents for multiple purpose
Monday, June 14, 2010
PAIR AND REMOTE PROGRAMMING
Pair programming is an agile software development technique in which two programmers work together at one work station.
One types in code while the other reviews each line of code as it is typed in. The person typing is called the driver. The person reviewing the code is called the observer (or navigator[1]).
The two programmers switch roles frequently (possibly every 30 minutes or less).
Its just like two University students sharing a single PC & coding together personally i did it whil e in University it was a great way of coding.
This is most acceptable at University level am not too sure if its in practice in the IT corporate world.
REMOTE PAIR PROGRAMMING :
Remote pair programming, also known as virtual pair programming or distributed pair programming, is the practice of pair programming where the two programmers comprising the pair are in different locations, working via a collaborative real-time editor, shared desktop, or a remote pair programming IDE plugin.
Remote pairing introduces difficulties not present in face-to-face pairing, such as extra delays for coordination, depending more on "heavyweight" task-tracking tools instead of "lightweight" ones like index cards, and loss of non-verbal communication resulting in confusion and conflicts over such things as who "has the keyboard".
Numerous tools, such as Eclipse plug-ins are available to support remote pairing. Some teams have tried VNC and RealVNC with each programmer using their own computer.This works well in our Organisation.
Others use the multi-display mode (-x) of the text-based GNU screen. Apple Inc. OSX has a built-in Screen Sharing application
Would like to share possible interview questions on selenium
Ans. Selenium is a set of tools that supports rapid development of test automation scripts for web based applications. Selenium testing tools provides a rich set of testing functions specifically
designed to fulfil needs of testing of a web based application.
Q2. What are the main components of Selenium testing tools?
Ans. Selenium IDE, Selenium RC and Selenium Grid
Q3. What is Selenium IDE?
Ans. Selenium IDE is for building Selenium test cases. It operates as a Mozilla Firefox add on and provides an easy to use interface for developing and running individual test cases or entire test
suites. Selenium-IDE has a recording feature, which will keep account of user actions as they are
performed and store them as a reusable script to play back.
Q4. What is the use of context menu in Selenium IDE?
Ans. It allows the user to pick from a list of assertions and verifications for the selected location.
Q5. Can tests recorded using Selenium IDE be run in other browsers?
Ans. Yes, Although Selenium IDE is a Firefox add on, however, tests created in it can also be run in other browsers by using Selenium RC (Selenium Remote Control) and specifying the name of the test suite in command line.
Q6. What are the advantage and features of Selenium IDE?
Ans.
1. Intelligent field selection will use IDs, names, or XPath as needed
2. It is a record & playback tool and the script format can be written in various languages including C#, Java, PERL, Python, PHP, HTML
3. Auto complete for all common Selenium commands
4. Debug and set breakpoints
5. Option to automatically assert the title of every page
6. Support for Selenium user-extensions.js file
Q7. What are the disadvantage of Selenium IDE tool?
Ans.
1. Selenium IDE tool can only be used in Mozilla Firefox browser.
2. It is not playing multiple windows when we record it.
Q8. What is Selenium RC (Remote Control)?
Ans. Selenium RC allows the test automation expert to use a programming language for maximum flexibility and extensibility in developing test logic. For example, if the application under test returns a result set and the automated test program needs to run tests on each element in the result set, the iteration / loop support of programming language’s can be used to iterate through the result set,calling Selenium commands to run tests on each item.
Selenium RC provides an API and library for each of its supported languages. This ability to use
Selenium RC with a high level programming language to develop test cases also allows the automated testing to be integrated with the project’s automated build environment.
Q9. What is Selenium Grid?
Ans. Selenium Grid in the selenium testing suit allows the Selenium RC solution to scale for test suites that must be run in multiple environments. Selenium Grid can be used to run multiple instances of Selenium RC on various operating system and browser configurations.
Q10. How Selenium Grid works?
Ans. Selenium Grid sent the tests to the hub. Then tests are redirected to an available Selenium RC, which launch the browser and run the test. Thus, it allows for running tests in parallel with the entire test suite.
Q 11. What you say about the flexibility of Selenium test suite?
Ans. Selenium testing suite is highly flexible. There are multiple ways to add functionality to Selenium framework to customize test automation. As compared to other test automation tools, it is Selenium’s strongest characteristic. Selenium Remote Control support for multiple programming and scripting languages allows the test automation engineer to build any logic they need into their automated testing and to use a preferred programming or scripting language of one’s choice. Also, the Selenium testing suite is an open source project where code can be modified and enhancements can be submitted for contribution.
Q12. What are the types of test can Selenium do?
Ans. Selenium is basically used for the functional testing of web based applications. It can be used for testing in the continuous integration environment. It is also useful for agile testing
It's great as a Regression Testing tool.
Q13. What is the cost of Selenium test suite?
Ans. Selenium test suite a set of open source software tool, it is free of cost.
Q14. What browsers are supported by Selenium Remote Control?
Ans. The test automation expert can use Firefox, IE 7/8, Safari and Opera browsers to run tests in Selenium Remote Control.
Q15. What programming languages can you use in Selenium RC?
Ans. C#, Java, Perl, PHP, Python, Ruby
Q16. What are the advantages and disadvantages of using Selenium as testing tool?
Ans. Advantages: Free, Simple and powerful DOM (document object model) level testing, can be used for continuous integration; great fit with Agile projects.
Disadvantages: Tricky setup; dreary errors diagnosis; can not test client server applications.
Q17. What is difference between QTP and Selenium?
Ans. Only web applications can be testing using Selenium testing suite. However, QTP can be used for testing client server applications. Selenium supports following web browsers: Internet Explorer, Firefox, Safari, Opera on different Operating Systems Windows, Mac OS X and Linux. However, QTP is limited to Internet Explorer on Windows.QTP uses scripting language implemented on top of VB Script. However, Selenium test suite has the flexibility to use many languages like Java, .Net, Perl, PHP, Python, and Ruby.
Q18. What is difference between Borland Silk test and Selenium?
Ans. Selenium is completely free test automation tool, while Silk Test is not. Only web applications can be testing using Selenium testing suite. However, Silk Test can be used for testing client server applications. Selenium supports following web browsers: Internet Explorer, Firefox, Safari, Opera on different Operating systems Windows, Mac OS X and Linux. However, Silk Test is limited to Internet Explorer and Firefox.
Silk Test uses 4Test scripting language. However, Selenium test suite has the flexibility to use many languages like Java, .Net, Perl, PHP, Python, and Ruby.
Wednesday, June 9, 2010
Executing selenium scripts
C:\Selenium>perl amazon.pl
ok 1 - open, /
ok 2 - type, twotabsearchtextbox, Microscope USB
ok 3 - click, //input[@alt='Go']
ok 4 - wait_for_page_to_load, 30000
ok 5 - is_text_present, Veho
ok 6 - click, link=Veho VMS004DELUXE USB Powered Microscope
ok 7 - wait_for_page_to_load, 300001..7
So here's how it happens
Selenium server waits there & launches the browser
So have a succesful first testcase.
I 'll add more of Data driven approach & executing a test suite.
Writing first test case in perl
All it does is gets into amazon.co.uk & searches for a microscope verifies if the brand exists & clicks on that link.
use strict;use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*iexplore",
browser_url => "http://www.amazon.com/" );
$sel->open_ok("/");
$sel->type_ok("twotabsearchtextbox", "Microscope USB");
$sel->click_ok("//input[\@alt='Go']");
$sel->wait_for_page_to_load_ok("30000");
$sel->is_text_present_ok("Veho");
$sel->click_ok("link=Veho VMS004DELUXE USB Powered Microscope");
$sel->wait_for_page_to_load_ok("30000");
Easy steps to go with installing Selenium RC for Perl
1.Start your Selenium server
You can create a batch file as below & just double click with start the server
add java -jar selenium-server.jar to a file & name that as seleniumserver.bat
2. Download Active Perl
3.Now you gotto install Test-WWW-Selenium packages.
4.Invoke perl package manager from your command prompt like this ppm
5.A GUI will open up search for Test-WWW
once you locate the selenium package on the list Run the marked actions.
So you are all set with the selenium packages that are required for you to get going.
Monday, May 10, 2010
Automation -Selenium-Perl
Here's the first things first :
-----------------------------
1.Install latest perl.
2.Download selenium client
3.execute the MakeFile.pl
4.then execute nmake (Here i hit an issue as i wasn't having Nmake15.exe on my windows box)
Install that if it cribs & then ensure we have that in your path.
5.It know cribs for
It looks like you don't have a C compiler on your PATH, so you will not beable to compile C or XS extension modules. You can install GCC from theMinGW package using the Perl Package Manager by running:
ppm install MinGW
http://www.mail-archive.com/perl-win32-users@listserv.activestate.com/msg38003.html
Am still on my way to resolve this .The above link wasn't of much help to me, at the moment.