In this series, We going to learn about the create a Test Suite in the Python. Let’s not waste much of the time lets start as quickly as possible.
Things you know before.
1. Selenium – Testing Framework
2. Python – Basic Python Syntax. – Please install it before proceeding.
3. Brain 😛
About Selenium :
If you have no clue what is selenium is,Read about Selenium in my other tutorials or you can have a look here for the more http://www.seleniumhq.org, Just for the quick reference, Selenium is Automation framework written in the java that allows you to automate the web application with the different languages support e.g Python,Javascript, Java, Ruby.You can write functional/acceptance tests using Selenium WebDriver.
Installing Python bindings for Selenium
Go to Command prompt or Terminal in the Mac and Type.
Make sure pip is installed on your system.(If not you can install it using this link here)
1 | pip install selenium |
It will install the python binding for the selenium to your system.
Step 1 : Running Selenium Server and Install Python Selenium bindings
Let’s run the Selenium Server that listens to our command/Test cases written python and execute them in the browser. Make sure java is installed on your system and its available in the path. If not follow this tutorial. And set up to path here
Download – Selenium server here.
1 | Run the Selenium Server with this command. |
1 | java -jar selenium-server-standalone-3.x.x.jar |
You will see something like this on the command line.
Selenium Server is up and Running.
Step 2 : Creating a Basic Test in the Selenium with Python and Run it.
Create a File in the Pycharm ( Python Editor) e.g I have made a Folder structure for the upcoming tutorials also. So This part is Part 1 and I have one file HelloWorld.py that will have the code for the First Test case in python.
In the File, we are going
1. Import the selenium web driver.
2. Create a driver object from FirefoxDriver Class and Open the Borwser.
3. Use get method to go to the URL.
4. Assert the title and Close the Brower.
Run the Test by
1 2 3 4 5 6 | from selenium import webdriver driver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title driver.close() |
File run using python:
1 | python HelloWorld.py |
So we have successfully run our first Test, Let’s move to the other Tutorial in the Next Part2.
Hope to see you guys in the next part.
[mc4wp_form id=”638″]
Don’t work.
>> pip install selenium
Collecting selenium
Using cached selenium-3.8.1-py2.py3-none-any.whl
Installing collected packages: selenium
Exception:
Traceback (most recent call last):
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py”, line 784, in install
**kwargs
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py”, line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py”, line 1064, in move_wheel_files
isolated=self.isolated,
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py”, line 345, in move_wheel_files
clobber(source, lib_dir, True)
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py”, line 316, in clobber
ensure_dir(destdir)
File “/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py”, line 83, in ensure_dir
os.makedirs(path)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py”, line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/selenium’
>> from selenium import webdriver
driver = webdriver.Firefox()
driver.get(“http://www.python.org”)
assert “Python” in driver.title
driver.close()
Users/aleksey/PycharmProjects/test/venv/bin/python /Users/aleksey/PycharmProjects/test/Part1/HelloWorld.py
Traceback (most recent call last):
File “/Users/aleksey/PycharmProjects/test/Part1/HelloWorld.py”, line 1, in
from selenium import webdriver
ModuleNotFoundError: No module named ‘selenium’
Process finished with exit code 1
Check your pip version if required use this guide to reinstall pip https://www.makeuseof.com/tag/install-pip-for-python/
Hi
I am facing this error.
ImportError: cannot import name ‘webdriver’ from ‘selenium
but the problem is I am not able to import webdriver in pycharm.
I tried importing webdriver from python interpreter and using terminal as well in both ways I am facing same error
ERROR: Could not find a version that satisfies the requirement webdriver (from versions: none)
ERROR: No matching distribution found for webdriver
Could you please help me how to resolve this error
Thanks