Download Python "bindings" for Selenium. Bindings are just some code that enables you to write tests using the Python programming language.
pip
installed. pip
is a Python's package manager. Basically, it allows you to get different code written in Python from they internet. Open Terminal and run which pip
. You should see a path to the pip installation, i.e. /usr/local/bin/pip
. If you don't, Google how to install pip
.pip install selenium
. You should get a confirmation that Selenium was installed. If you get errors, try figuring them out.Allow Remote Automation
.import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class GoogleSearchTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Safari()
def test_search_returns_expected_result(self):
driver = self.driver
driver.get("<http://www.google.com>")
search_text_field = driver.find_element_by_name("q")
search_text_field.send_keys("Let me google that for you")
self.wait_for(seconds=3)
search_text_field.send_keys(Keys.RETURN)
self.wait_for(seconds=3)
expected_result = "LMGTFY - Search Made Easy"
assert expected_result in driver.page_source
def wait_for(self, seconds=0):
time.sleep(seconds)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()