class WebKey(object):

    def __init__(self, txt, timeout=30):
        # 构造函数,创造必要的实例变量
        if txt == 'gg':
            self.driver = webdriver.Chrome()
            self.driver.maximize_window()
            self.driver.implicitly_wait(timeout)
        elif txt == 'ff':
            self.driver = webdriver.Firefox()
            self.driver.maximize_window()
            self.driver.implicitly_wait(timeout)
        elif txt == 'ie':
            self.driver = webdriver.Ie()
            self.driver.maximize_window()
            self.driver.implicitly_wait(timeout)
        else:
            print("浏览器暂不支持")
            pass

    def load_url(self, url=None):
        """
        打开网站
        :param url: 网站地址
        :return:
        """
        self.driver.get(url)

# 登录业务
def login_busin(user, passwd):
    br = WebKey()
    br.open_br(br="gg")
    br.open_url(URL)
    br.sleep(tm=1)
    br.send_key(section='LoginAccountElements', option='username', data=user)
    br.send_key(section='LoginAccountElements', option='password', data=passwd)
    picture_address = br.screenshot(os.path.join(img_address, str(int(time.time())) + ".png"))
    text = read_image.ocr(picture_address)
    br.send_key(section='LoginAccountElements', option='Verification', data=text)
    br.click(section='LoginAccountElements', option='Login')
    br.sleep(tm=1)
    br.sleep(5)
    # br.close()

if __name__ == '__main__':
    pass
# 添加业务
class add_actual_pop(WebKey):

    def add_actual_population(self, name, phone, id_card):
        self.click(section="HomePageElements", option="Basic_database")
        self.click(section="Basic_database_main", option="add_Basic_population")
        self.send_key(section="add_Basic_population_jump", option="name", data=name)
        self.click(section="add_Basic_population_jump", option="date_birth")
        self.send_key(section="add_Basic_population_jump", option="date_birth_input", data="2011-01-11")
        pyautogui.typewrite(['enter'])
        self.click(section="add_Basic_population_jump", option="Current_address")
        self.send_key(section="add_Basic_population_jump", option="Current_address_search", data='舟山市岱山县驸马宫前西南约150米')
        self.click(section="add_Basic_population_jump", option="Current_address_query")
        self.click(section="add_Basic_population_jump", option="Current_address_click")
        self.click(section="add_Basic_population_jump", option="Current_address_confirm")
        self.click(section="add_Basic_population_jump", option="House_registration")
        self.click(section="add_Basic_population_jump", option="House_registration_register")
        self.click(section="add_Basic_population_jump", option="gender")
        self.click(section="add_Basic_population_jump", option="male")
        self.send_key(section="add_Basic_population_jump", option="phone_num", data=phone)
        self.send_key(section="add_Basic_population_jump", option="id_card", data=id_card)
        self.click(section="add_Basic_population_jump", option="entry_status")
        self.click(section="add_Basic_population_jump", option="entry_status_atypism")
        self.click(section="add_Basic_population_jump", option="confirm")
        self.sleep(tm=10)
        self.close()


if __name__ == '__main__':
    pass
# 用例

@pytest.fixture()
def test_login():        #登录用例
    login_busin(user="ctz", passwd="admin123456?")


def test_add_actual_pop(test_login):        # 添加用例
    add_actual_pop().add_actual_population(name="原始人", phone="15255225552", id_card="420101199706214387")

if __name__ == '__main__':
    pass


↙↙↙阅读原文可查看相关链接,并与作者交流