ord在python中的用法_在ord中用python脚本运行函数

我正在使用selenium webdriver创建一个用python编写的测试套件。但是,当我运行测试时,我得到一个错误:“PythonOrgSearch”对象没有属性“driver”

我很确定这是因为测试没有按顺序运行,所以驱动程序在测试完成之前关闭。我以前也遇到过错误:“试图在没有建立连接的情况下运行命令”,我想这也表明测试没有按顺序运行,所以驱动程序没有启动?我不确定这是否准确,只是我最好的猜测。我的代码看起来像:import unittest

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

import os

import time

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

from selenium.webdriver.common.action_chains import ActionChains

from urllib.request import urlopen

from html.parser import HTMLParser

gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))

binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')

driver = webdriver.Firefox(firefox_binary=binary, executable_path=gecko+'.exe')

class PythonOrgSearch(unittest.TestCase):

#sets up driver to run tests

def setUp(self):

self.driver = driver

self.driver.start()

def test_opens(self):

driver.get("url.com")

driver.find_element_by_id('username').send_keys('user')

driver.find_element_by_id('password').send_keys('pass')

driver.find_elements_by_css_selector("button[type='submit']")[0].click()

time.sleep(2);

self.assertIn("title", driver.title)

def ztearDown(self):

self.driver.close()

if __name__ == "__main__":

unittest.main()

编辑:我添加了驱动程序=自驱动程序在每个功能开始时

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值