Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

cuongld2
cuongld2

Posted on

     

Python fundamentals for automation test

I. About PythonII. 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 libsIV. Git InstallationV. 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
Enter fullscreen modeExit fullscreen mode

I. About Python

Python is a general flexible programming language.

Alt Text

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:
Enter fullscreen modeExit fullscreen mode

Please go to official site of Python for download : Python download site

Alt Text

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

Alt Text

  1. Check for installation correctly or not:

After installation success, go to system environment variables to check for path.

Alt Text

Check if python is installed correctly:

Open Command Prompt -> python --version

→ It should shows the current python version is : 3.7.4

Alt Text

Some simple REPL python:
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode
print('Hello World')a=5b=100a+b105quit()toendcurrentrepl
Enter fullscreen modeExit fullscreen mode

Alt Text

  1. 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 installInstall python via homebrew
Enter fullscreen modeExit fullscreen mode
  1. For Linux:

Please follow this guide python-for-linux

  1. 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:
Enter fullscreen modeExit fullscreen mode

Go to pip official site for installation : Pip official site

Check if pip is installed by this command: pip --version

Alt Text

  1. 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

Alt Text

Or you can install the local lib from source code by:
Enter fullscreen modeExit fullscreen mode

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 installDownload and install pycharm community from jetbrains site : Pycharm IDE
Enter fullscreen modeExit fullscreen mode

Alt Text

Alt Text

  1. 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
Enter fullscreen modeExit fullscreen mode

Alt Text

Alt Text

Clone project in pycharm
Enter fullscreen modeExit fullscreen mode

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 :
Enter fullscreen modeExit fullscreen mode

Go to the location for stored project source code

cd stored_project

git clonehttps://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
Enter fullscreen modeExit fullscreen mode

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

  1. Types can be "immutable", "mutable"

For example : string type is immutable

But list is mutable

Alt Text

  1. 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 moduleInheritance from parent class : class name (BaseClassName):
Enter fullscreen modeExit fullscreen mode

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
famduong profile image
PhamDuong
Learning, Searching, make the world better
  • Location
    Ha noi
  • Joined

hey guy. this post is big help for my first steps on automation testing. Thanks a lot! :D

CollapseExpand
 
cuongld2 profile image
cuongld2
Learning ishard work, but everything you learn is yours and will make subsequent learningeasier.

Thanks for your comment.
It means a lot to me.
Other incoming posts awaited.
Stay tune.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Learning ishard work, but everything you learn is yours and will make subsequent learningeasier.
  • Location
    Hanoi, Vietnam
  • Joined

More fromcuongld2

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp