找不到夹具“自我”

时间:2018-11-29 12:10:24

标签: python appium pytest

我是Pytest-bdd的新手。我正在尝试运行BDD测试,但是灯具始终存在相同的问题。这是我的代码。我尝试了没有@ pytest.fixture的情况,仅通过@given gherkin步骤获得了相同的结果。找不到灯具“自我”

import os
from appium import webdriver
from time import sleep
import pytest
from pytest_bdd import scenario, given, when, then, parsers

@pytest.fixture(autouse=True, scope='module')
def Setup (self):
    "Setup for the test"
    desired_caps = {}
    self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)

def Teardown():
    self.driver.quit()

@scenario('features.feature','Prueba1')
@given('step 1')
def test_single_player_mode(self):
    element1=self.driver.find_element_by_id("com.nestle.bagzielicious.beta:id/on_button_vegan")
    element1.click()
    sleep(1)

2 个答案:

答案 0 :(得分:0)

通常,这些方法都在类内,然后self引用该类。

例如:

from unittest import TestCase


class DriverTestCase(TestCase):

答案 1 :(得分:0)

使用Pytest尝试以下代码:

import os
from appium import webdriver
from time import sleep
import pytest
from pytest_bdd import scenario, given, when, then, parsers

@pytest.fixture(autouse=True, scope='module')
def driver():
    "Setup for the test"
    desired_caps = {}
    driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
    yield driver
    driver.quit()

@scenario('features.feature','Prueba1')
@given('step 1')
def test_single_player_mode(driver):
    element1=driver.find_element_by_id("com.nestle.bagzielicious.beta:id/on_button_vegan")
    element1.click()
    sleep(1)