Tuesday, August 13, 2013

Handling Keyboard & Mouse Events in Selenium

Handling special keyboard and mouse events : It contains the Actions and the Action classes that are needed when executing these events.

ClickAndHold() : Clicks (without releasing) at the current mouse location.ContextClick() : Performs a context-click at the current mouse location.
DoubleClick() : Performs a double-click at the current mouse location.
dragAndDrop(source, target) : Performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
keyDown(modifier_key) : Performs a modifier key press. Does not release the modifier key - subsequent interactions may assume it's kept pressed.
Parameters:
modifier_key – any of the modifier keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)

keyUp(modifier _key) : Performs a key release.
Parameters:
modifier_key – any of the modifier keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)

moveByOffset(x-offset, y-offset) : Moves the mouse from its current position (or 0,0) by the given offset.
Parameters:
x-offset- horizontal offset. A negative value means moving the mouse left.
y-offset- vertical offset. A negative value means moving the mouse up.

moveToElement(toElement) : Moves the mouse to the middle of the element. Parameters:
toElement- element to move to.

Release() : Releases the depressed left mouse button at the current mouse locationsendKeys(onElement, charsequence) : Sends a series of keystrokes onto the element. Parameters:
onElement - element that will receive the keystrokes, usually a text field
charsequence – any string value representing the sequence of keystrokes to be sent.

Monday, August 12, 2013

Introduction to Selenium Grid

What is Selenium Grid?

 Selenium Grid is a part of the Selenium Suite that specializes on running multiple tests across different browsers, operating systems, and machines in parallel.

Selenium Grid has 2 versions –
Grid 1 and Grid 2.

Use of Selenium Grid


Run your tests on different browsers, operating systems, and machines all at the same time. This will ensure that the application you are testing is fully compatible with a wide range of browser and OS combinations.
    Save time in execution of your test suites. If you set up Selenium Grid to run, say, 4 tests at a time, then you would be able to finish the whole suite around 4 times faster.

Difference between Grid 1.0 and Grid 2.0


Grid 1.0

1. Selenium Grid 1 has its own remote control that is different from the Selenium RC server.
2. You need to install and configure Apache Ant first before you can use Grid 1.
3. Can only support Selenium RC commands/scripts.
4. You can only automate one browser per remote control.


Grid 2.0

1. Selenium Grid 2 is now bundled with the Selenium Server jar file
2. You do not need to install Apache Ant in Grid 2.
3. Can support both Selenium RC and WebDriver scripts.
4. One remote control can automate up to 5 browsers.


 Hub and Node


The hub is the central point where you load your tests into.

  • Only one hub should be in a grid.
  • The hub is launched only on a single machine.
    The Nodes
  • Nodes are the Selenium instances that will execute the tests that you loaded on the hub.
  • There can be one or more nodes in a grid.
  • Nodes can be launched on multiple machines with different platforms and browsers.


Selenium Grid is used to run multiple tests simultaneously in different browsers and platforms.
  • Grid uses the hub-node concept.
  • The hub is the central point wherein you load your tests.
  • Nodes are the Selenium instances that will execute the tests that you loaded on the hub.
  • To install Selenium Grid, you only need to download the Selenium Server jar file – the same file used in running Selenium RC tests.
  • There are 2 ways to verify if the hub is running: one was through the command prompt, and the other was through a browser
  • To run test scripts on the Grid, you should use the DesiredCapabilities and the RemoteWebDriver objects.
  • DesiredCapabilites is used to set the type of browser and OS that we will automate
  • RemoteWebDriver is used to set which node (or machine) that our test will run against.