selenium3+python3配置csv文件

通过设置csv文件的意义:从csv文件中读取参数,例如登录的用户名和密码,如果修改了密码,不需要改动脚本,只需要改动csv文件的值就可以了。

在执行目录下建一个.csv的文件
再建一个.py的文件,代码如下

# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.action_chains import *
import unittest
import time
import csv

dates = csv.reader(open("D:\\Pychrom project\\cvs\\login.csv",'r'))
list = []
for date in dates:
    if date == 0:
        pass
    else:
        list.append(date)
print(list)
print(list[0][0])
print(list[1][0])
print(list[2][0])
class TestLogin(unittest.TestCase):
    """"test login case"""
   
    def test_login(self):

        """test login with cell phone number"""
        print("test login.")
        self.driver.find_element_by_xpath("//div[@class='hd-fBtn-user']").click()
        phone = self.driver.find_element_by_xpath("//span[@class='eico eico-phone']")
        ActionChains(self.driver).click(phone).perform()
        self.driver.find_element_by_xpath("//input[@placeholder='手机号或邮箱']").clear()
        self.driver.find_element_by_xpath("//input[@placeholder='手机号或邮箱']").send_keys(list[0][0])
        self.driver.find_element_by_xpath("//input[@placeholder='密码']").clear()
        self.driver.find_element_by_xpath("//input[@placeholder='密码']").send_keys(list[1][0])
        self.driver.find_element_by_xpath("//input[@class='ping gl-btnLog login_mail_btn']").click()
        time.sleep(10)
        
        #登录断言
        """""use the assertEqual function"""
        self.assertEqual(login_name, list[2][0], msg="login failed")


if __name__ == '__main__':

    unittest.main()

分析

三个地方用到了参数化
1.输入邮箱
2.输入密码
3.断言里的判断

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值