Monday, 24 June 2013

Handling switch over from one window to another using Selenium Webdriver

This script helps you to switch over from a Parent window to a Child window and back cntrl to your Parent Window

String parentWindow = driver.getWindowHandle();
Set<String> handles =  driver.getWindowHandles();
for(String windowHandle  : handles)
      <!--Perform your operation here for new window-->
driver.close(); //closing child window
    driver.switchTo().window(parentWindow); //cntrl to parent window

Tuesday, 4 June 2013

Cross-browser testing on Cloud using Python + RC + Sauce Labs

Generally, cross browser tests are done manually on Browserstack;  We can do the same using Selenium with Python bindings.

Selenium RC: JSON configuration
Sauce-specific settings are given inside Selenium's "browser" parameter. This is generally a string in the form "*browser" (e.g. "*iexplore", "*firefox"), but will now need to be a full JSON object like this:

"username": "your username here",
 "access-key": "your access key here",
 "os": "Linux",
 "browser": "firefox",
 "browser-version": "3"

Python Code:

#! /usr/bin/env python
#-.- coding=utf8 -.-

from selenium import selenium
import unittest, time, re

class login(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("",
                                     "username": "your-sauce-username",
                                     "access-key": "your-access-key",
                                     "os": "Linux",
                                     "browser": "firefox",
                                     "browser-version": "20"
    def test_empty_info(self):
        sel = self.selenium"/in/")"id=button-login")
        sel.type("id=username", "james")
        sel.type("id=password", "connor")"id=Login")
        try: self.assertEqual("Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help.", sel.get_text("css=div.loginError"))
        except AssertionError, e: self.verificationErrors.append(str(e))

    def tearDown(self):
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":

Note:- Reports are generated as log and video