Tuesday, February 9, 2010

Selenium - Handling Dialogs with Python

I am currently scripting Selenium tests using Python (selenium.py)
One of the main issues I have found are looping, parametrization and handling modal dialogs

Dialogs:

Dialog boxes are invisible to selenium, it just can't see them.
The reason is the dialogs are native to the operating system you are running.
Selenium only identifies the web components (elements)

In Internet Explorer I created a work around for handling dialogs in Python such as File Download, SaveAs, Save and Close. This workaround could also be used for other dialogs.
Although this may not be the most elegant method it works for me.


import os, sys, time
import win32com
from pywinauto import application
import winGuiAuto as wga
import time
import SendKeys
import win32gui
import win32con


###############################
class AutoTools:
def __init__(self):

self.app = application.Application()


def clickFileDL(self):
"""
Find the Download Dialog and Click "Save"
"""
time.sleep(5)

# Draw and Outline so I know it's the right control and give focus to the control
self.app.FileDownload["&Save"].DrawOutline()
time.sleep(1)
# Click the Save Button
self.app.FileDownload["&Save"].ClickInput()
time.sleep(1)
# Get a Handle to the File Download Window by title
hwnd = wga.findTopWindow(wantedText="File Download")
time.sleep(1)
# Simulate Mouse Down and Mouse Up
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, 0, 0)
# Important timing issue between clicks
time.sleep(2)
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, 0)
#
SendKeys.SendKeys("""{ENTER}""")

def clickSaveAs(self):
"""
Find the Save As Dialog and Click "Save"
"""
time.sleep(1)
self.app.SaveAs.PrintControlIdentifiers()
self.app.SaveAs.ComboBox3.Select("All Files")
# Find the Save As Dialog and Click "Save"
self.app.SaveAs.Save.DrawOutline()
time.sleep(1)
self.app.SaveAs["&Save"].ClickInput()
time.sleep(1)
SendKeys.SendKeys("""{ENTER}""")


def clickDLClose(self):
"""
Find the Downloadcomplete Dialog and Click "Close"
"""

time.sleep(1)
# Find the Download complete Dialog and Click "Close"
time.sleep(2)
SendKeys.SendKeys("""{ENTER}""")

#########################################

Refs:
http://pywinauto
.openqa.org/

http://www.brunningonline.net/simon/blog/.../winGuiAuto.py.html


Next I will explain how to use Autoit with FireFox to handle dialogs...

Sunday, December 27, 2009

Selenium and Python

I have been working on Selenium at my latest project and I found that selenium of course is not capable of controlling IE dialogs such as File Download and SaveAs. So far in Python I have been able to work around this but using a combination of pyWinAuto.py,SendKeys and winGuiAuto

You have to get focus to the control, Send and Up/down mouse command and and "ENTER" command. I have know idea why it takes all those commands but it works.

I have also written a reporting tool for Selenium that show how many test have been run and the results in HTML format.

Selenium is nice if you have to automate many browsers such as IE and Firefox.

Friday, April 17, 2009

Working with WinForm dataGridViews and QuickTest Pro

With Quick Test Pro I found the example below works the best when you want to select and click the cell.

' Select the cell row 0 column zero
SwfWindow("myForm").SwfTable("dataGridView1").SelectCell 0,0

' Click the cell row 0 column zero
SwfWindow("myForm").SwfTable("dataGridView1").ClickCell 0,0

Minimize the QuickTest Pro window

Here is a quick way to Minimize the QuickTest Pro window when running tests

' Minimize the QuickTest Pro window
Public Function MinimizeQTPWindow ()
Set qtApp = getObject("","QuickTest.Application")
qtApp.WindowState = "Minimized"
Set qtApp = Nothing
End Function

Logic Studio Pro 8

Well I finally broke down and decide to buy Logic Studio Pro 8. It has a done of features that will take me a bit to utilize. I can now do some quality recordings

My current music editing system is:
Hardware:
20 " Intel based IMac - 3Gig mem, 2.0 GHz Dual Core
140 gig usb external drive
60 gig usb external drive
M-Audio audio interface
Behringer Mixer PreAmp
Software:
Logic Studio Pro 8
Garageband
Audacity

Music Site: myspace.com/musicofbericlak

I found Audacity and excellent tool for audio editing and capture samples.
Hopefully soon I can gave some demos for all to hear

Wednesday, March 18, 2009

March 18 2009

Creating New Installer for PAMIE 3.0. There will also be some Video tutorials on http://showmedo.com/. ShowMeDo is a great site for llearning new technology!!

Tuesday, March 3, 2009

PAMIE 3.0 almost complete! Runs with Python v3.0

Doing the final testing of PAMIE 3.0 this week. PAMIE is a python app that will allow you to Automate Internet Explorer. It is not 100% but it will allow you get most things automated for testing and development.

This is a little bit of a rewrite in Python 3.0 of the original cPAMIE.py file.
This allowing you automate Internet Explorer with Python 3.0!!

Cheers
Rob