美文网首页
firecontrol项目自动化代码-持续更新

firecontrol项目自动化代码-持续更新

作者: DD丿 | 来源:发表于2021-04-19 09:19 被阅读0次

导包


# 对应lib套件下的webui文件中 声明的 open_browser, mgr_login 方法

from lib.webuiimport open_browser, mgr_login

from hytestimport *

from hytestimport STEP, INFO, CHECK_POINT

from timeimport sleep

from seleniumimport webdriver

# 导入Select类

from selenium.webdriver.support.uiimport Select

# 初始化(英文叫 setup 方法)操作

# 与初始化正好相反的操作就是 清除(teardown方法 )。

# 谁做的初始化操作对环境产生了 什么改变 , 谁 就应该在 清除 操作里面做什么样的 还原 。


# cases套件下/登录 单元测试(需要调用webui中登录模块代码)  

class DD0001:

    name= '消防DD0001'

    # 初始化方法setup  登录模块

    # 对象wd调用lib/webui中open_browser,mgr_login()

    def setup(self):

      open_browser()

        # mgr_login()

    # 清除方法teardown    清除浏览器对象wd中全局存储对象 GSTORE的代码

    def teardown(self):

        INFO('清除初始化 执行下方用例')

        wd= GSTORE['wd']

        # 随便引用下wd

        wd.find_element_by_xpath('//*[@id="root"]/section/main/section/main')

测试用例步骤正式开始!


    def teststeps(self):

        STEP(1,'添加警情')

        wd= GSTORE['wd']

        # 添加警情

        wd.find_element_by_class_name('add_list').click()

        sleep(1)

        # 录入警情

        sleep(1)

        wd.find_element_by_xpath(

            '/html/body/div[1]/section/section/main/div/div/div[2]/div/div[2]/div[1]/div[2]/input').send_keys('崇明丁丁测试')

        sleep(1)

        # 起火地点

        wd.find_element_by_xpath(

            '/html/body/div[1]/section/section/main/div/div/div[2]/div/div[2]/div[3]/div[2]/input').click()

        sleep(1)

        wd.find_element_by_xpath(

            '/html/body/div[1]/section/section/main/div/div/div[2]/div/div[2]/div[3]/div[2]/input').send_keys('崇明')

        sleep(1)

        # 放弃了,时间抓不到==

        # js = document.getElementById('请选择时间').removeAttribute("placeholder")

# document.execute_script(js)

        # # 时间控件没有点击事件,直接send值

        # wd.find_element_by_xpath('//*[@id="root"]/section/section/main/div/div/div[2]\

# /div/div[2]/div[2]/div[2]/span/div/input').send_keys('2021-04-13 11:24:46')

        # 所属乡镇选择

        # 创建Select对象 代表下拉选择框元素

        select= Select(

            wd.find_element_by_class_name(

                '/html/body/div[1]/section/section/main/div/div/div[2]/div/div[2]/div[4]/div[2]/span/span/span[1]/span').click())

        sleep(1)

        # 通过 Select 对象选中所属乡镇

        select.select_by_visible_text("新国村")

        wd.find_element_by_xpath(

            '/html/body/div[1]/section/section/main/div/div/div[2]/div/div[2]/div[4]/div[2]/span/span/span[1]/span').click()


lib下webui.py代码

from hytestimport *

from hytestimport STEP, INFO, CHECK_POINT

from timeimport sleep

from seleniumimport webdriver

# 我们在创建 WebDriver 对象后,把它存到了 hytest 全局存储对象 GSTORE 中。 方便其他的代码 获取。

# 公共代码‘登录’放入lib库中

# 声明open_browser对象 打开浏览器

def open_browser():

    INFO('打开浏览器至消防页面')

    # 创建浏览器对象wd/调用驱动打开chrome

    wd= webdriver.Chrome(r'c:\webdrivers\chromedriver.exe')

    #浏览器最大化

    wd.get_window_size()

    wd.maximize_window()

    wd.get('http://firecontrol.console.rayjeak.com/sign/login')

    sleep(2)

    wd.find_element_by_id('userName').send_keys('')

    wd.find_element_by_id('password').send_keys('')

    sleep(2)

    # 登录

    wd.find_element_by_xpath('//*[@id="root"]/section/main/section/main/form/div[4]/div/div/span/button').click()

    sleep(2)

    #以下代码表示将上方登录代码存入GSTORE对象中方便调用 存入是GSTORE在前

    GSTORE['wd'] = wd

# # 登录firecontrol

def mgr_login():

    # 调用是wd对象在前

    wd= GSTORE['wd']

    wd.get('http://firecontrol.console.rayjeak.com/sign/login')

    wd.find_element_by_id('userName').send_keys('')

    wd.find_element_by_id('password').send_keys('')

    wd.find_element_by_xpath('//*[@id="root"]/section/main/section/main/form/div[4]/div/div/span/button').click()

sleep(2)

相关文章

网友评论

      本文标题:firecontrol项目自动化代码-持续更新

      本文链接:https://www.haomeiwen.com/subject/wxldlltx.html