So, you need to automate, and you have never written a line of code before or it’s been a while. Fortunately, this isn’t a problem. The  Helium API gives you simple commands and straightforward documentation to help get you started. It all begins and ends with Selenium, and if you need quick results this is the way to go.

One of the benefits of Selenium is that you can pick from a few languages to work with. I decided to go with Python, as I was familiar with it, and it’s easy to pick up if you don’t code often or at all. You’ll find it’s actually more difficult to setup your development environment than it will be to get your first script running.

So let’s get started…

Install Python, Eclipse, JDK and PyDev Recently, Android Studio replaced Eclipse as the official IDE for Android so you won’t be able to get Eclipse from the usual place.

  1. Install Python from https://www.python.org/downloads/

  2. For Windows, make sure you check the option to install it in the PATH

  3. Install Eclipse for Java Developers from http://www.eclipse.org/downloads/

  4. For Mac, install the 64-bit version

  5. For Windows, install the 32 or 64 bit version depending on your OS

  6. Install the latest version of the JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html

  7. For Windows, install the x86 or 64 bit version depending on your OS

  8. Edit eclipse.ini.

  9. For Mac:

  10. Right click on the Eclipse application, choose Show Package Contents and navigate to /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini and open it

  11. Append the following lines to the bottom of the file (be sure to replace the version number with yours):

  12. -vm

  13. /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java

  14. For Windows

  15. Navigate to the same folder as the Eclipse application and open eclipse.ini

  16. -vm

  17. C:\Program Files (x86)\Java\jdk1.8.0_25\bin\javaw.exe

  18. Download the latest version of PyDev from SourceForge at http://sourceforge.net/projects/pydev/files/pydev/.

  19. Unzip its contents to /Applications/eclipse/dropins (or wherever you have Eclipse installed) and restart Eclipse, if opened.

Helium Setup

  1. Download the Helium library from http://heliumhq.com/download

  2. Extract the contents of the download

  3. Place the extracted folder where you want to keep it

  4. Open a terminal window and set your PYTHONPATH as described here: http://heliumhq.com/docs/getting_started

  5. So, the only catch with Helium is that it is not directly compatible with Safari. You have to do some magic to get it all working, but here is a great article out there that walks you through the process:

  6. https://lavanyaaraga.wordpress.com/2013/01/19/installation-steps-of-selenium-webdriver-in-mac-safari-browser/

  7. For Windows / IE 11:

  8. Follow the instructions for installing a registry key here: http://heliumhq.com/docs/internet_explorer

Install Selenium I realize that this post is about Helium, but I also quickly realized that I was going to have to learn Selenium. Don’t let this stop you though. Use Helium to get some traction and you will find yourself writing Selenium in no time.

  1. For Mac:

  2. Open Terminal

  3. Run “pip install selenium.” If you don’t have full permission on your Mac, type “sudo pip install selenium”

  4. For Windows

  5. Open a command prompt

  6. Navigate to C:\Python34\Scripts

  7. Run “pip.exe install selenium”

  8. Download the latest version of Selenium Server (formerly the Selenium RC Server) form: http://www.seleniumhq.org/download/

  9. For Internet Explorer:

  10. Download the 32 or 64 bit driver for IE from: http://www.seleniumhq.org/download/

  11. Extract it

  12. Complete the “Required Configuration” as described here: https://code.google.com/p/selenium/wiki/InternetExplorerDriver

  13. For Chrome, install the ChromeDriver:

  14. For Mac:

  15. https://sites.google.com/a/chromium.org/chromedriver/downloads - download the latest version with the link noted with “Mac32”

  16. Unzip and put the file in /Users/*name*/local/lib/node_modules/appium/build/chromedriver/windows

  17. For Windows:

  18. https://sites.google.com/a/chromium.org/chromedriver/downloads - download the latest version with the link noted with “Win32”

  19. Put the chromedriver.exe file in C:\Python34\Scripts folder.

Environment Setup

  1. Launch Eclipse

  2. Choose your working folder (if first time launching it)

  3. Choose PyDev in the top right of the window or…

  4. Click Window

  5. Click Open Perspective - Other…

  6. Click PyDev

  7. Click “File - New… - PyDev Project”

  8. Complete the following on the form:

  9. Project Name

  10. Project Type

  11. Grammar Version

  12. Interpreter

  13. You will have to click the link under this drop down and choose automatic setup if you have not set up a project before

  14. Click "Create ‘src’ folder and add it to the PYTHONPATH

  15. Working sets

  16. Check “Add project to working sets”

  17. Choose one or add one

  18. You have to do this or you won’t be able to access your files in the Eclipse IDE

  19. Click Finish

  20. Right Click the project you just created

  21. Click Properties

  22. Click PyDev - PYTHONPATH

  23. Click External Libraries

  24. Click Add source folder

  25. Navigate to and click the “helium-python-X.X.X\heliumlib” folder

  26. Click OK

  27. Click Add zip/jar/egg

  28. Navigate and click the “selenium-server-standalone-2.44.0.jar” file

  29. Click “Force restore internal info”

  30. Click OK Create a package (just a directory for your source)

  31. Expand your project tree

  32. Right Click on the “src” folder

  33. Click New - PyDev Package

  34. Enter a name

  35. Click Finish Create a module (just a source file, in this case a “.py” file)

  36. Right Click on a package

  37. Click New - PyDev Module

  38. Enter a name

  39. Click Finish

  40. Click OK

Now you are ready to code! If you find yourself asking where you should go from here, reference the Helium API docs and the many Python resources on the internet. The Helium site provides a few examples that you can actually run and find your way.

Here a few pointers as you figure all of this out…

  • StackOverflow is your best friend - what a great community of developers

  • Do not search for “helium” unless you want to fill some balloons. Search for “selenium” and work through the information that is out there. The Helium commands correlate to Selenium commands and it’s a great way to start picking up Selenium.

  • Use the browser developer console and pull the objects “CSS Path” for reference in your code.

    • How to use CSS Path with Helium:

      • Open your browser and go to webpage

      • Right click on an element, i.e. button, clickable text, etc…

      • Click Inspect Element

      • Right click the highlighted section in the developer console

        • You may need to do some refinement of the click area here - as you drag your mouse over the code you will see the highlight change
      • Click Copy CSS Path

      • Enter it as follows in you code: click(S(csspath))

    • A step further, make a variable for each CSS Path so you can easily reference them anywhere in the code

  • Make your functions small - don’t do too much at once so that you can reuse code as much as possible

Launching Safari This is all you need to launch Safari after completing the setup instructions above. You cannot use Helium commands, however, the last line “set_driver(driver)” passes the driver to Helium so you can execute the rest of your scripts in Helium.

import OS 
from selenium import webdriver 
os.environ["SELENIUM_SERVER\_JAR"] = "// _your path_ /selenium-server-standalone-2.44.0.jar" 
driver = webdriver.Safari() 
driver.get(" [https://www.google.com/](https://www.google.com/ "https://www.google.com/")") 
set_driver(driver) 

Launching IE I was having issues launching IE with helium, although it should work, so I did it with Selenium. Same as Safari above, the last line “set_driver(driver)” passes the driver to Helium so you can execute the rest of your scripts in Helium.

from selenium import webdriver 
driver = webdriver.Ie() 
driver.get(" [https://www.google.com/](https://www.google.com/ "https://www.google.com/")") 
set_driver(driver)