zoukankan      html  css  js  c++  java
  • 调用Excel或Oracle数据,数据加载,selenium等使用实例

    from selenium import webdriver
    from common.Excel import ExcelUtil
    from common.Oracle import OracleUtil
    import ddt, os
    import unittest
    import time

    try:
    # ---------------Excel封装调用取表中数据---------------------------
    filePath = os.path.join("..\Excel\test.xlsx")
    sheetName = "Sheet1"
    test_data = ExcelUtil(filePath, sheetName).dict_data()
    print(test_data)


    except:
    # ---------------调用Oracle取数据库中取数据-------------------------
    oracl = OracleUtil()
    sql = "select t.user_name, t.psw from th_user_info_ t where t.user_id is not null"
    s = oracl.oracle_getrows(sql)
    print(type(s))
    for i in s:
    s2 = ('username', 'psw', 'STATUS', 'CREATE_TIME', 'FANS_NAME')
    s3 = (dict(zip(s2, i)))
    test_data = []
    test_data.append(s3)
    print(test_data)


    @ddt.ddt
    class TestLogin(unittest.TestCase):
    @classmethod
    def setUp(cls):
    cls.driver = webdriver.Firefox()
    print(cls.driver)
    cls.driver.get("http://www.baidu.com/")
    cls.driver.maximize_window()
    cls.driver.find_element_by_link_text("登录").click()
    time.sleep(10)
    cls.driver.find_element_by_xpath(".//*[@id='TANGRAM__PSP_3__footerULoginBtn']").click()

    def login(self, username, psw):
    self.driver.find_element_by_xpath(".//*[@id='TANGRAM__PSP_3__userName']").send_keys(username)
    self.driver.find_element_by_xpath(".//*[@id='TANGRAM__PSP_3__password']").send_keys(psw)
    self.driver.find_element_by_xpath(".//*[@id='TANGRAM__PSP_3__submit']").click()
    time.sleep(10)

    @ddt.data(*test_data)
    def test_login(self, data):
    print("测试数据%s" % data)
    # 调用登录方法
    self.login(data['username'], data['psw'])

    @classmethod
    def tearDown(cls):
    cls.driver.quit()


    if __name__ == "__main__":
    unittest.main()
  • 相关阅读:
    聚类算法学习-kmeans,kmedoids,GMM
    hdu
    高仿精仿微信应用ios源码下载
    UVA 116 Unidirectional TSP 经典dp题
    [置顶] 动态规划之切割钢条
    poj
    求解printf函数?
    实现多文件上传在iOS开发中
    开源DirectShow分析器和解码器: LAV Filter
    <Win32_20>纯c语言版的打飞机游戏出炉了^_^
  • 原文地址:https://www.cnblogs.com/wapn/p/9613619.html
Copyright © 2011-2022 走看看