我有一个使用selenium IDE导出到python的selenium webdriver测试用例.然后想添加一些额外的功能,以便在selenium测试用例之间插入自定义代码.
现在的问题是 - 如果我犯了一个错误或自定义编写的python代码返回错误 - 仍然selenium测试用例继续执行
我希望如果出现这样的错误,就停止执行selenium测试用例.通过简单的谷歌搜索,然后使用shutil模块的日志移动代码复制了下面的场景
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import os, shutil
class SeleniumException(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.co.in/"
self.verificationErrors = []
self.attachment = 1
self.file_source_location = "F:\\python_test\\logfiles\\"
self.file_move_location = "F:\\logfiles_back\\"
def test_selenium_exception(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("gbqfq").clear()
driver.find_element_by_id("gbqfq").send_keys("Check this out")
if self.attachment:
try:
for contents in os.listdir(self.file_source_location):
src_file = os.path.join(self.file_source_location, contents)
dst_file = …Run Code Online (Sandbox Code Playgroud) python selenium exception-handling webdriver selenium-webdriver
我正在尝试从 python 文件执行 selenium 测试用例。我知道可以使用 python 的子进程模块来完成 - 但我想探索调用测试用例函数的可能性。
这是我的代码
from selenium import w ebdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import os, shutil, sys
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
class SeleniumException(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
#self.driver = nested_selenium.driver
self.base_url = "https://www.google.co.in/"
self.verificationErrors = []
def test_selenium_exception(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("gbqfq").clear()
driver.find_element_by_id("gbqfq").send_keys("Check this out")
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what) …Run Code Online (Sandbox Code Playgroud)