pytest data driven pandas

pytest data driven pandas

The main process: Use pandas to read the data in excel, then perform Baidu query and assert

pf = pd.read_excel('data_py.xlsx', usecols=[1,2])

print(pf.values)

输出:

[[‘听妈妈的话’ ‘周杰伦’]
[‘遇见’ ‘孙燕姿’]
[‘伤心太平洋’ ‘任贤齐’]]



pf = pd.read_excel('data_py.xlsx', usecols=[1,2])
data_res = pf.values



@pytest.mark.parametrize('name, result_content', data_res)
class Test_py(object):
  def setup(self):
    self.driver = webdriver.Chrome()
    self.driver.get("https://www.baidu.com")
    time.sleep(1)


  def test_q(self, name, result_content):
    self.driver.find_element_by_id("kw").send_keys(name)
    time.sleep(1)
    self.driver.find_element_by_id('su').click()
    time.sleep(2)
    #断言搜索结果是否包含对应的内容
    assert  result_content  in  self.driver.page_source

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

if __name__=="__main__":
  pytest.main()

 How to obtain information

【Message 777】

Friends who want to get the source code and other tutorial materials, please like + comment + collect , three times in a row!

After three consecutive rounds , I will send you private messages one by one in the comment area~

Guess you like

Origin blog.csdn.net/GDYY3721/article/details/132279502