6-3-3ios自动化-数据驱动

https://testerhome.com/topics/14247

#!/usr/bin/env python3
# coding:utf-8
from appium import webdriver
import time,selenium,openpyxl,unittest

class testCheat(unittest.TestCase):
    def setUp(self):
        self.wb=openpyxl.load_workbook("ms.xlsx",data_only=True)
        self.wb.guess_types=True
        self.sh=self.wb['工作表 1']
        self.caps={}
        self.caps['bundleId']='com.taobaobj.moneyshield'
        self.caps['newCommandTimeout']=600
        self.driver=webdriver.Remote("http://192.168.43.86:8100/wd/hub",self.caps)
        time.sleep(5)

    def find_element(self,xpath,timeout=30):
        deadline=time.time()+timeout
        while time.time() < deadline:
            try:
                el=self.driver.find_element_by_xpath(xpath)
                return el
            except Exception as e:
                time.sleep(0.5)
        raise RuntimeError("Element not found ")

    def test_ch(self):
        for row in self.sh.rows:
            if row[3].value not in ['yes',]:
                continue
            print(row[0].value,row[1].value)
            op=row[0].value
            xpath=row[1].value
            if op =='click':
                self.find_element(xpath).click()
            if op == 'assert':
                self.find_element(xpath)
            if op=='send_keys':
                self.find_element(xpath).send_keys(row[4].value)

    def tearDown(self):
        self.driver.quit()

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

excel表格

原文地址:https://www.cnblogs.com/csj2018/p/9671269.html