Friday 30 March 2012

Selenium IDE and CAPTCHA


Selenium can only be used to test a web app protected by CAPTCHA if a human involved for the test. So, if you are automating registration form of any site that includes a CAPTCHA, you will require human interaction during the specific section that requires a CAPTCHA response.

There are two ways in which you can automate CAPCHA
1.By break command
2.By input-box

Suppose after command 3, there is CAPTCHA

1.By break command

Command 1
Command 2
Command 3
4th command will be
Break
Enter CAPTCHA manually and resume execution of test
continue with your next commands

2.By input-box
Command 1
Command 2
Command 3
4th command will be
storeEval | prompt(“Enter value for captcha”); |variable
type | locator of CAPTCHA field | ${variable}
continue with your next commands



Saturday 3 March 2012

Selenium supported browsers


Below are the browsers which selenium supports :


  *firefox
  *mock
  *firefoxproxy
  *pifirefox
  *chrome
  *iexploreproxy
  *iexplore
  *firefox3
  *safariproxy
  *googlechrome
  *konqueror
  *firefox2
  *safari
  *piiexplore
  *firefoxchrome
  *opera
  *iehta

Debugging Tests in Selenium IDE


Below are the methods or ways of Debugging your selenium IDE scripts..

Selenium IDE reports failures in the log console, and failed test cases within the suite are shown in red.
The failing test cases and commands are highlighted in red, so it’s easy to see what failed, but quite often it can be difficult to understand why it failed. This information is all in the log, but if you’ve run more than just a couple of tests then it will be difficult to match up the failing commands to the errors in the log.

There are a few ways to debug these failures and work out if your application under test has bugs, or perhaps your tests require some changes

Execute Individual Command:


When you double-click a command in Selenium IDE it will be executed – this is very handy when first writing your tests. You could use this to step through each command in each test case until you find a failure, and investigate from there.

Custom Log Messages:

There’s a command in Selenium IDE named echo and this will basically repeat whatever you type into the log when the test is executed. You could use this to output a message associated with an expected failure, and then find this in the log. You do still have to scroll through the log to look for your messages though.

Slow Down:
You can use the speed slider to slow down how fast your test commands are executed. This can be helpful as you can watch the application under test while your tests are running and see any obvious issues that your tests are failing on. You can also use this in combination with executing commands manually by pausing your tests.

Pause, Break and Step:

You can pause your test at any time, either by clicking the Pause icon in the toolbar or by setting breakpoints. Set a breakpoint by right-clicking on a command you want Selenium IDE to pause before executing, and selecting ‘Toggle Breakpoint’ from the context-menu. You will see a small pause icon appear to the left of your command.
When Selenium IDE is paused, the Step icon becomes available. You can use this to execute one command at a time, which can be very useful when approaching a failure or working through a number of verification failures. If you have set multiple breakpoints then you can click the Resume icon to continue executing your tests and stop at the next breakpoint.

Set Start Point:

If you have a really long test and it’s failing towards the end, then you can set a custom start point so that you don’t have to run the entire test when you’re investigating the failure. For example, your test might register a new user, log in, and then fail on the welcome page. You could simply navigate to the welcome page yourself and set your test to start from there. To set a start point simply right click on the first command you want Selenium IDE to execute and click ‘Set / Clear Start Point’. You will see a small play icon appear to the left of your command.

There are many ways that Selenium IDE can assist you in investigating failures and debugging your tests.

Selenium IDE -Get Current Time, Date, Month and Year


Current Time - javascript{(new Date().getHours()+" : " + new Date().getMinutes() + " : " + new Date().getSeconds())}

Current year - javascript{(new Date()).getFullYear()}

Current Month - javascript{(new Date().getMonth()) + 1}

Current date - javascript{(new Date().getDate().toString())}

Selenium IDE - Locating Elements in Page.

For most of the Selenium commands target is required. This target identifies an element in the content of the web application. The various locator types are:
1. Identifying elements by ID
2. Identifying elements by Name
3. Identifying elements by Link
4. Identifying elements by XPath
5. Identifying elements by CSS
6. Identifying elements by DOM

For identifying elements, we need some applications.

FireBug: Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

We can download this from this website: http://getfirebug.com/.
Just Drag and Drop firebug.xpi to Firefox it will install.

With the help of FireBug you can
1. Identifying elements by ID
2. Identifying elements by Name



Identifying elements by DOM


Few examples for DOM
getElementById()
getElementsByName()
getElementsByTagName()
getElementsByClassName()



identifier=id
Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id.
(This is normally the default; see below.)
id=id
Select the element with the specified @id attribute.
name=name
Select the first element with the specified @name attribute.
  • username
  • name=username

The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
  • name=flavour value=chocolate


dom=javascriptExpression


Find an element using Javascript traversal of the HTML Document Object
Model. DOM locators must begin with "document.".
  • dom=document.forms['myForm'].myDropdown
  • dom=document.images[56]


xpath=xpathExpression
Locate an element using an XPath expression.
  • xpath=//img[@alt='The image alt text']
  • xpath=//table[@id='table1']//tr[4]/td[2]


link=textPattern
Select the link (anchor) element which contains text matching the
specified pattern.
  • link=The link text


css=cssSelectorSyntax
Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors
for more information. You can also check the TestCssLocators test in
the selenium test suite for an example of usage, which is included in
the downloaded selenium core package.
  • css=a[href="#id3"]
  • css=span#firstChild + span

Selenium IDE - Add two number stored in variable



store          | 10 |  a
store          | 5   |  b
storeEval   | ${a}+${b} | total
echo         |${total}