51Testing软件测试论坛
标题:
python2.7+selenium3---求教各位大神
[打印本页]
作者:
测试小白文
时间:
2017-7-18 17:37
标题:
python2.7+selenium3---求教各位大神
使用xml文件做“数字驱动测试”
代码如下:
info.xml[code]<?xml version="1.0" encoding="utf-8"?>
<catalog>
<explain>中国移动139邮箱</explain>
<url>http://mail.10086.cn/</url>
<all_null username="" password="">请输入帐号</all_null>
<pawd_null username="testingwtb" password="">请输入邮箱密码</pawd_null>
<user_null username="" password="a123456">请输入帐号</user_null>
<yes username="15919825333" password="******">15919825333</yes>
<error username="xxx" password="xxx">帐号或密码错误</error>
</catalog>
复制代码
py文件如下:
#coding:UTF-8
from selenium import webdriver
import unittest
from xml.dom import minidom
dom = minidom.parse('C:\\Users\\Administrator\\Desktop\\info.xml')
root = dom.documentElement
class Test_139(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Ie()
self.driver.implicitly_wait(30)
logns = root.getElemntByTagName('url')
self.url =logns[0].firstChild.data
self.verificationErrors= []
def test_all_null(self):
driver = self.driver
driver.get(self.url)
longs = root.getElemntByTagName('all_null')
username = longs[0].getAttribute('username')
password = longs[0].getAttribute('password')
Text = longs[0].firstChild.data
driver.find_element_by_name('UserName').send_keys(username)
driver.find_element_by_class_name('Password').send_keys(password)
driver.find_element_by_id('loginBtn').click()
test = driver.find_element_by_id('tip_user_msg').text
self.assertEqual(test, Text)
if __name__ == '__main__':
unittest.main()
复制代码
运行后报错了,如下:
Traceback (most recent call last):
File "D:\Escplise\workspace\Pytest\src\test001\test\test003.py", line 7, in <module>
dom = minidom.parse('C:\\Users\\Administrator\\Desktop\\info.xml')
File "C:\Python27\lib\xml\dom\minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "C:\Python27\lib\xml\dom\expatbuilder.py", line 924, in parse
result = builder.parseFile(fp)
File "C:\Python27\lib\xml\dom\expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 9
复制代码
,小白一个,不知道错误原因,求大神帮助!!!
作者:
finomy
时间:
2017-7-19 09:30
“info.xml[code]” xml文件最前面的这个是做什么用的?感觉是xml文件格式的问题。你把info.xml[code]删掉试试看。还有看一下xml文件的编码,编码有可能不是utf8
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2