I. About Python
II. Install Python :
Get and install from official site:
2. Check for installation correctly or not:
3. For MacOS:
4. For Linux:
5. Python virtual environment:
III. Install pips and other libs:
Install pip:
2. Install other libs
IV. Git Installation
V. Pycharm IDE
2. Simple Configuration and usage:
2.1 : Fresh new project:
2.2 : Clone projects from other source:
VI. Python types and basic structures
I. About Python
Python is a general flexible programming language.
Currently we have 2 major versions of Python : Python 2 and Python 3. But Python 2 will not be supported from 2020.
Besides, Python3 with a lot of active changes make it easy for development and maintenance ( easy to handle with strings, non ASCII character..)
II. Install Python :
Get and install from official site:
Please go to official site of Python for download : Python download site
Go for the latest version : currently latest version is 3.7.4
Notes: In Win 7, please if install Python 3, please install version 3-7-3 ( does not work with 3-7-4)...
Install Python from exe
- Check for installation correctly or not:
After installation success, go to system environment variables to check for path.
Check if python is installed correctly:
Open Command Prompt -> python --version
→ It should shows the current python version is : 3.7.4
Some simple REPL python:
REPL stands for Read Evaluate Print Loop, and is the name given to the interactive MicroPython prompt that is accessible on the Pycom devices
From Command Prompt :→ python
→ print('Hello World')
a = 5
b = 100
a+b → 105
quit() to end current repl
- For MacOS:
Usually python2 is already installed in MacOS and you cannot uninstall python2
Next thing you need to do is to install Python3 along with existing python2
There are 2 options to install Python3:
Go to Python official site and download the package to install
Install python via homebrew
- For Linux:
Please follow this guide python-for-linux
-
Python virtual environment:
Manually create virtual environment : virtual environment python
Or you can create project with virtual environment interpreter by your favorite IDE (For example : Pycharm)
III. Install pips and other libs:
Install pip:
Go to pip official site for installation : Pip official site
Check if pip is installed by this command: pip --version
-
Install other libs
Most of the times, you would install python lib via pip
pip install
For current usage, to install all required libs that take to do automated testing in python, please install with the following requirements.txt
text fileEdit file
pip install -r requirements.txt
To verify if the library is installed or not, type in command prompt, for example to check pytest is installed or not: pytest --version
Or you can install the local lib from source code by:
pip install
For example:
pip install C:\Users\cuongld\PycharmProjects\pytest-testrail
IV. Git Installation
Go to git installation page : git-installation-page
Check git is installed or not : git --version
V. Pycharm IDE
There are 3 major versions of Pycharm : Enterprise, Community, Education
Download and and install
Download and install pycharm community from jetbrains site : Pycharm IDE
- Simple Configuration and usage: 2.1 : Fresh new project:
File → New project → Choose the framework to work with or pure python
2.2 : Clone projects from other source:
I will give example for github project
Go to github page stored project
→
Clone project in pycharm
VCS → Check out from version control → Git → HTTPS Clone
(If the project is private, or only allowed certain accounts to access→ you may need to input username, password in pycharm)
Or by command line :
Go to the location for stored project source code
cd stored_project
git clone https://username:password@github.com/username/repository.git
After clone successfully, open project in Pycharm:
File -> Open -> Choose project directory.
VI. Python types and basic structures
Every things is an object
For example, in Java, to create a function, you must assign that to be long a class ( or interface..)
But in Python, you can create a function alone in the module
- Types can be "immutable", "mutable"
For example : string type is immutable
But list is mutable
-
Basic usage:
Create new instance of class: instance_class = Class_name()
Python use indentation for understand code block
To call a function in within a class, must use with self, for example :
class SettingsElements(BasePageElement):
def find_continue_where_left_off(self,driver):
self.find_shallow_element()
Import can be local or global in module
Inheritance from parent class : class name (BaseClassName):
Top comments (2)
hey guy. this post is big help for my first steps on automation testing. Thanks a lot! :D
Thanks for your comment.
It means a lot to me.
Other incoming posts awaited.
Stay tune.