web自动化脚本

from time import sleep
import time
import sys
from selenium import webdriver
import unittest
from selenium.webdriver.common.by import By
from case_1 import url, username, password


class test01(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://www.baidu.com:9099/#/")
        self.driver.find_element_by_class_name("username").send_keys("admin")
        self.driver.find_element_by_class_name("password").send_keys("admin.njmk")
        # 点击登陆按钮
        self.driver.find_element_by_xpath(".//*[@id='react-content']/div/div[2]/form/a").click()
        # 浏览器最大化
        self.driver.maximize_window()
        sleep(1)

    def tearDown(self):

        sleep(2)
        self.driver.find_element_by_css_selector(".navbarlsta.personmenu>span").click()
        sleep(1)
        self.driver.find_element_by_xpath(".//*[@id='personal']/div/div[2]/div[2]/button").click()
        self.driver.quit()

    def test001(self):
        driver = self.driver
        driver.implicitly_wait(30)
        # 点击导航栏
        driver.find_element_by_css_selector(".icon.iconfont.icon-Expand").click()
        sleep(1)
        # 点击传染病管理主菜单
        driver.find_element_by_xpath(".//*[@id='lteNav']/li[6]/p/p/span").click()
        sleep(1)
        # 点击死亡病例报告卡子菜单
        driver.find_element_by_xpath(".//*[@id='reportQuery$Menu']/li[3]/a").click()
        sleep(1)
        # 点击出动上报
        driver.find_element_by_xpath("/html/body/div/div/div[3]/div/div[2]/div[1]/form/button[3]").click()
        """输入必填项"""

        # 输入正确的ID号
        driver.find_element_by_xpath(".//*[@id='patientId']").send_keys("123345")

        # 输入ICD 编码
        driver.find_element_by_xpath(".//*[@id='ICDNum']").send_keys("798")
        # 点击病人科室
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[1]/div[3]/div/div[2]/div/div/div").click()
        # 选择产科病区
        driver.find_element_by_xpath("//ul/li[contains(text(),'产科病区')]").click()
        # 患者类型选择住院
        driver.find_element_by_xpath(".//*[@id='patientType']/label[2]/span[2]").click()
        # 输入正确的住院号
        driver.find_element_by_xpath(".//*[@id='registeredNum']").send_keys("121212")
        # 点击省
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[3]/div[1]/div/div[2]/div/div/div").click()
        # 选择广西
        driver.find_element_by_xpath("//ul/li[contains(text(),'广西')]").click()
        # 点击市
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[3]/div[2]/div/div[2]/div/div/div").click()
        # 选择柳州
        driver.find_element_by_xpath("//ul/li[contains(text(),'柳州')]").click()
        # 点击区
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[3]/div[3]/div/div[2]/div/div/div").click()
        # 选择城中区
        driver.find_element_by_xpath("//ul/li[contains(text(),'城中区')]").click()
        # 点击民族
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[4]/div[3]/div/div[2]/div/div/div").click()
        # 选择壮族
        driver.find_element_by_xpath("//ul/li[contains(text(),'壮族')]").click()

        # 死者姓名输入   小李
        driver.find_element_by_xpath(".//*[@id='deathName']").send_keys("小李")

        # 性别选择 男
        driver.find_element_by_xpath(".//*[@id='deathSex']/label[1]/span[2]").click()
        # 点击出生日期
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[5]/div[3]/div/div[2]/div/span/div/input").click()
        # 选择2017-08-09
        driver.find_element_by_xpath("html/body/div[8]/div/div/div/div/div[1]/div/input").send_keys("2017-08-09")
        # 文化程度选择文盲
        driver.find_element_by_xpath(".//*[@id='degree']/label[1]/span[2]").click()
        # 有效证件类型选择身份证
        driver.find_element_by_xpath(".//*[@id='idenType']/label[2]/span[2]").click()
        # 证件号码输入 211022201708092345
        driver.find_element_by_xpath(".//*[@id='idenNum']").send_keys("211022201708091234")
        # 婚姻状况选择未婚
        driver.find_element_by_xpath(".//*[@id='marital']/label[1]/span[2]").click()
        # 个人身份选择其他
        driver.find_element_by_xpath(".//*[@id='ownIden']/label[18]/span[1]/input").click()
        sleep(1)
        # 其他输入 刚出生的
        driver.find_element_by_xpath(".//*[@id='other']").send_keys("刚出生的")
        # 点击死亡时间
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[9]/div[1]/div/div[2]/div/span/div/input").click()
        # 死亡日期选择今天
        driver.find_element_by_xpath("html/body/div[9]/div/div/div/div/div[2]/div[3]/span/a").click()
        # 点击时间
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[9]/div[2]/div/div/div/span/input").click()
        # 选择 13:15:12
        driver.find_element_by_xpath("html/body/div[10]/div/div/div/div[1]/input").send_keys("13:15:12")
        sleep(1)
        # 失去焦点
        driver.find_element_by_xpath(".//*[@id='rcDialogTitle0']").click()
        # 死亡地点 选择家中
        driver.find_element_by_xpath(".//*[@id='deathErea']/label[3]/span[2]").click()
        sleep(1)
        """常用住址选择  河北唐山市路北区文化路街道22村33门牌号"""
        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[11]/div[1]/div/div[2]/div/div/div").click()
        sleep(1)
        driver.find_element_by_xpath("html/body/div[11]/div/div/div/ul/li[3]").click()  # 河北

        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[11]/div[3]/div/div/div/div/div").click()
        driver.find_element_by_xpath("//ul/li[contains(text(),'唐山市')]").click()

        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[11]/div[5]/div/div/div/div/div").click()
        driver.find_element_by_xpath("//ul/li[contains(text(),'路北区')]").click()

        driver.find_element_by_xpath(
            "html/body/div[2]/div/div[2]/div/div[1]/div[2]/form/div/div[2]/div[1]/div[11]/div[7]/div/div/div/div/div").click()
        driver.find_element_by_xpath("//ul/li[contains(text(),'文化路街道')]").click()

        driver.find_element_by_xpath(".//*[@id='cunC']").send_keys("22")
        driver.find_element_by_xpath(".//*[@id='haoC']").send_keys("33")

        sleep(2)
        js1 = "window.scrollTo(0,1000)"
        driver.execute_script(js1)
        # 直接死亡原因选择  病毒性上呼吸道感染
        driver.find_element_by_xpath(".//*[@id='deathBeacaseA']").send_keys("病毒性上呼吸道感染")
        driver.find_element_by_xpath("//ul/li[contains(text(),'病毒性上呼吸道感染')]").click()
        # 根本死亡原因选择 原发性呼吸道结核
        driver.find_element_by_xpath(".//*[@id='deathRoot']").send_keys("特指呼吸道结核,细菌学、病理(+)")
        driver.find_element_by_xpath("//ul/li[contains(text(),'特指呼吸道结核,细菌学、病理(+)')]").click()

        # 最高诊断单位选择  三甲医院
        driver.find_element_by_xpath(".//*[@id='highestUnit']/label[1]/span[2]").click()
        # 最高诊断依据选择 尸检
        driver.find_element_by_xpath(".//*[@id='highestBasis']/label[1]/span[2]").click()
        sleep(1)

        driver.find_element_by_xpath(".//*[@id='deathEg']").send_keys("自动化")

        # 被调查者签字
        driver.find_element_by_xpath(".//*[@id='investigatorSigned']").send_keys("小李")
        # 被调查者姓名
        driver.find_element_by_xpath(".//*[@id='investigatorName']").send_keys("小李")
        # 与死者关系
        driver.find_element_by_xpath(".//*[@id='relationship']").send_keys("自动化")
        # 输入联系电话
        driver.find_element_by_css_selector("#investigatorTel").send_keys("18888888888")
        # 联系地址或工作单位   自动化
        driver.find_element_by_xpath(".//*[@id='investigatorWord']").send_keys("自动化")
        # 死因推断  自动化
        driver.find_element_by_xpath(".//*[@id='deathBecase']").send_keys("自动化")
        # 调查者签字
        driver.find_element_by_xpath(".//*[@id='signed']").send_keys("自动化")
        # 点击调查日期框
        driver.find_element_by_xpath("html/body/div[6]/div/div[2]/div/div[1]/div[2]/form/div[2]/div[2]/div/div[5]/div[2]/div/div[2]/div/span/div").click()
        sleep(3)
        # 点击保存
        driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div/div[1]/div[3]/button[1]").click()

        try:
            # 是否提示 必填项
            text = driver.find_element_by_css_selector(".ant-form-explain").text
            print("提示信息:", text)
            # 断言

            self.assertIn("不能为空,请输入", text)
        except AssertionError:
            print("获取的sys.exc_info()信息为:", sys.exc_info()[1])
            nowtime = time.strftime("%Y_%m_%d %H_%M_%S")
            print("时间格式为:", nowtime)
            driver.get_screenshot_as_file("../Image/%s-%s.jpg" % (nowtime, "test_028新增_死者生前病例及症状体征为空"))
            # 抛异常
            raise
        # 点击取消
        driver.find_element_by_xpath("html/body/div[2]/div/div[2]/div/div[1]/div[3]/button[2]").click()


if __name__ == '__main__':
    unittest.main()

猜你喜欢

转载自blog.csdn.net/cyy19920319/article/details/82961720