如果 Python 中的 pytest 通过或失败,如何修改代码以返回

问题描述 投票:0回答:0

我在 selenium IDE(firefox 扩展)中记录了一个网站测试。我将代码导出为 pytest,但是,当我将它粘贴到 py 脚本(+ 运行它的代码)时,测试会执行预期的操作,但不会输出 OK 或 FAILED。在selenium IDE中所有的测试步骤都是绿色的,甚至是测试的标题,表明测试通过了。我试图添加一个@pytest 夹具。我可以添加一个断言函数,但是,在我看来,它是检查测试是否返回预期的结果,在我的例子中,我想检查代码是否通过。

# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class TestWikipedia():
  def setup_method(self, method):
    self.driver = webdriver.Firefox()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()

  def test_wikipedia(self):
    self.driver.get("https://www.wikipedia.org/")
    self.driver.set_window_size(577, 668)
    self.driver.find_element(By.ID, "searchInput").click()
    self.driver.find_element(By.ID, "searchInput").send_keys("selenium IDE")
    self.driver.find_element(By.ID, "searchInput").send_keys(Keys.ENTER)   
      
testClass = TestWikipedia()

testClass.setup_method("")
testClass.test_wikipedia()
testClass.teardown_method("")
python pytest selenium-ide
© www.soinside.com 2019 - 2024. All rights reserved.