29 November 2012

Python and SST Frameworks


I updated some tests here to cover a website navigation.  Using SST was a bit more difficult then using Watir.  Mainly because SST doesn't have a lot of coverage for page elements that have no id's... so you have to get more creative. 

For example, they don't  have api methods to handle clicking on a link with only a class element.  So to get around that you  have to look for the text itself (which is usually a fragile idea) or use some other method to find the class and then click on it.

So here's some examples of me using SST with Python:
https://github.com/wbwarnerb/Python_Beachbody/blob/master/Pages/Home.py




25 November 2012

Getting a Python Web Automation Framework going

I've so far been able to get GEB (groovy based web automation) up and running at home... (although it was very difficult) and I've been able to get Cucumber up and running on a web automation stack (very easy) and tonight I think I got a Python stack up and running.

Python was a bit tricky.  Although not as easy to set up as Cucumber, it certainly isn't as difficult as GEB.

Some pitfalls with Python:
  1. You can't easily use Python 3.* Due to compatibility issues with selenium webdriver, Python 3 isn't really supported. I did see some 3rd party scripts to try and bridge that compatibility, but it looked like a dangerous path to go down.
  2. You need to install Python 2.7.3.
  3. After python, you'll need to install setuptools.  If on windows, setuptools has a nice windows installer.  This is the pre-requisite to get PIP (a python package installer) up and running.
  4. You will need a package installer (i.e. PIP) - if you're on windows, PIP's website doesn't really offer much help for you.  Windows users have to download https://raw.github.com/pypa/pip/master/contrib/get-pip.py directly since windows doesn't have curl natively.  
  5. Once you have the get-pip.py, you just run the thing... then pip.exe will be in your python*/Scripts folder. 
  6. Run pip install sst  OR use a IDE (i'm using jetbrains' Pycharm) to point to sst and install.
Once SST is installed and part of your project, you can write a simple test like this:
from sst.actions import *

go_to('http://www.ubuntu.com/')
assert_title_contains('Home | Ubuntu')
close_window()


Be sure to check the SST doc's for referencing their actions, but they are pretty straight forward and similar to native webdriver and selenium actions: http://testutils.org/sst/actions.html

Now you can start building out your framework... I've heard of some BDD python based layers (Nose and Lettuce) out there, but they aren't supported by my IDE (jetbrains see's little community backing BDD in python) so I haven't gone that route.

Uploaded a sample of this code at github:
https://github.com/wbwarnerb/Python_Beachbody

24 November 2012

Python 3 and webdriver incompatible?

I've been looking at this idea of using python with webdriver, in a automation framework.  It seems though that webdriver doesn't support Python 3.

This is pretty frustrating.  I'm mostly interested in languages from the point of view of automation.  I pick up a language and download the latest stable version, and find there is no support on it from any web automation framework... not even webdriver. 

So it looks like Python must be running version 2.* and not 3.* in order to access webdriver.


python basics - whitespace and indentations

This might be obvious to some - but I didn't know about indentations.  In Python indentations within a method, have to be the same.  So this will work:

def main():
    print("something to say")
    print("is something to say")

but this won't -
def main():
    print("something to say")
  print("is something to say")

But this will work:
def main():
    print("something to say")
print("is something to say")

The first example does indentation as Python expects within a method.
The second example fails because the indention is not the same.
The third example works, but will first run the line print("is something to say") and then execute the line in the method, if we have the line:
if __name__ == "__main__": main()
This is because the line is at the same level of the method def.  So it's run first.
Either way the third case is valid, as the last print is at the level of the method.

23 November 2012

python - calling functions before they are defined

Been picking up some python and I noticed that you can define a function in a non linear way... meaning the method call could come before defining the method:

def main():
      function2()

def function2():
     print("this is the second funciton.")

if __name__ == "__main__": main()

That last line there is saying run the file and then the main function after.  So function2() called in main gets defined first.  Then main is run, so it knows what function2() is.

11 November 2012

My Rails Comment Application

I'm taking some courses on Rails.  I built out a web application that uses some 3rd party api's like Devise (for authentication).  The web application is set up to let users create accounts, and post status updates.  I went ahead and published the early version of the app with Heroku:
http://infinite-waters-3206.herokuapp.com/

heroku rake db:migrate

When publishing a database to Heroku, remember to always use heroku rake db:migrate, or else the heroku rails app won't work.