Automated test environment setup in a Mac environment here is a pro-measured article.
But there are two points to note in this process:
1. Execute command "sudo pip install–u Selenium" in terminal networking if it fails, you can try to install selenium with the command "sudo easy_install selenium";
2. Install the pycharm after the new project,interpreter must be selected, the default given two options are likely to be wrong. A interpreter passed by the pro-test is "/usr/bin/python2.7". If you choose the wrong interpreter when you create project, you can Community Edition from Pycharm (my pycharm version is Pycharm 5.0.1 File->default settings-) >default project->project Interpreter->add Local to re-choose, such as:
If the 2nd choice is incorrect, the import Selenium error, the hint: unresolved preference ' Selenium '.
Only after the selection of interpreter to the normal introduction of selenium and execute the program (following the test Blog Park login function as an example):
#-*-coding: UTF-8-*-
from selenium import webdriver
import time
browser = webdriver.Firefox ()
browser.get ("http://cnblogs.com")
time.sleep (1)
browser.find_element_by_link_text ("login"). click ()
time.sleep (1)
browser.find_element_by_id ("input1"). send_keys ("user name")
browser.find_element_by_id ("input2"). send_keys ("password")
browser.find_element_by_id ("signin"). click ()
time.sleep (1)
try:
if browser.find_element_by_link_text ("Exit"):
print "Login Successfully."
except:
print "Login failed."
# browser.quit ()
Run results (test pass):
This is done with a simple test case under Mac+python+pycharm+selenium.
Application Python+selenium for Web Automation testing under MAC OS