current position:Home>Some integration operations on Web pages in Python

Some integration operations on Web pages in Python

2022-05-15 02:38:22Koki can test a rookie

One 、 The first is to open the to be tested UI Automated operations :
Log class [ Poke it here ], The last class is , You can quote .


from selenium import webdriver
import time
from common.log import *

def OpenURL(url):
    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches",["enable-automation"])
    driver = webdriver.Chrome(options=options)
    if str("https") in url:
        driver.get(url)
        driver.implicitly_wait(1)
        driver.maximize_window()
        try:
            driver.find_element_by_id("details-button").click()  #  If you can't access directly , You need to open the Advanced menu option plus 
            time.sleep(1)
            driver.find_element_by_id("proceed-link").click()
            time.sleep(1)
        except Exception as error:
            Log().logMsg(1,error.args)
            # print("test_api's, error is {0}", format(error))
            # raise error
    else:
        driver.get(url)
        driver.maximize_window()

Two 、 Write a public class , Then use a file to call it , In this way, multiple problems are omitted, and the call is omitted A lot of code .

First file ,case file

class CaseStep:

    def __init__(self):
        self.Step = 0
        self.Behavior = ''
        self.operationPage = ''
        self.Description = ''
        self.ObjctName = ''
        self.PositioningExpression = ''
        self.InputValue = ''
        self.OutputValue = ''
        self.ExpectedResult = ''
        self.WaitTime = 0
        self.Enabled = 1
        self.IgnoreErr = 0
        self.LoopCnt = 1

class ElementMap:
    def __init__(self):
        self.Page = ''
        self.Type = ''
        self.Name = ''
        self.TmpText = ''
        self.SourceName = ''

class Case:
    def __init__(self):
        self.caseSteps = list()
        self.elementMaps = list()



Second document :ibehavior_handler.py

from models.case import *

class IBehaviorHandler:
    def handle_behavior(self,selenium_wd_class, step:CaseStep):
        """ :param selenium_wd_class: :param step: :return: """

This is to associate the methods in the first file and the second file .

copyright notice
author[Koki can test a rookie],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/132/202205120517584746.html

Random recommended