У Thread.local нет атрибута - Owasp Zap, веб-драйвер, салат для автоматического тестирования безопасности

Недавно я участвовал в тестах безопасности, интегрированных с автоматизированными функциональными тестами. Я нашел интересную статью, и я хочу проверить это решение. При запуске с использованием структуры салата, он получает ошибку

"Thread_.local object has no attribute" driver "in file gruyere.py

terrain.py

import os
import subprocess
from lettuce import before, world, after
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.webdriver.firefox.firefox_binary import  FirefoxBinary
from time import sleep
from zapv2 import ZAPv2
from pprint import pprint

@before.all
def open_shop():
    start_zap_server()
    firefox_profile = prepare_firefox_profile()
    open_drivers(firefox_profile)

def start_zap_server():
    subprocess.Popen(['bin/zap_2.4.2/zap.sh','-daemon', '-config api.disablekey=true'],stdout=open(os.devnull,'w'))
    world.zap = ZAPv2(proxies={'http': 'http://127.0.0.1:8090', 'https': 'https://127.0.0.1:8090'})
    sleep(5)

def prepare_firefox_profile():
    zap_proxy_host = "127.0.0.1"
    zap_proxy_port = 8090
    firefox_profile = webdriver.FirefoxProfile()
    firefox_profile.set_preference("network.proxy.type", 1)
    firefox_profile.set_preference("network.proxy.http", zap_proxy_host)
    firefox_profile.set_preference("network.proxy.http_port", int(zap_proxy_port))
    firefox_profile.set_preference("network.proxy.ssl",zap_proxy_host)
    firefox_profile.set_preference("network.proxy.ssl_port", int(zap_proxy_port))
    firefox_profile.set_preference("browser.startup.homepage", "about:blank")
    firefox_profile.set_preference("startup.homepage_welcome_url", "about:blank")
    firefox_profile.set_preference("startup.homepage_welcome_url.additional", "about:blank")
    firefox_profile.set_preference("webdriver_assume_untrusted_issuer", False)
    firefox_profile.set_preference("accept_untrusted_certs", True)
    firefox_profile.update_preferences()
    return firefox_profile

def open_drivers(firefox_profile):
    world.driver = get_firefox(firefox_profile)
    world.driver.set_page_load_timeout(20)
    world.driver.implicitly_wait(20)
    world.driver.maximize_window()

def get_firefox(firefox_profile):
    # Locate Firefox from the default directory otherwise use FIREFOX_BIN #
    try:
        driver = webdriver.Firefox(firefox_profile=firefox_profile)
    except Exception:
        my_local_firefox_bin = os.environ.get('FIREFOX_BIN')
        firefox_binary = FirefoxBinary(my_local_firefox_bin)
        driver = webdriver.Firefox(firefox_binary=firefox_binary)
    return driver

Gruyere.feature

Feature: Gruyere

  Scenario: Gruyere
    Given I navigate to Gruyere
    When I choose to Agree & Start
    Then I am taken to "Gruyere: Home"

    Given I choose to Sign Up
    When I choose to Create Account with user name 
"blue" and password "cheese"
    Then I am taken to "Gruyere: Error"

    Given I choose to Sign In
    When I choose to Login with user name "blue" and     password "cheese"
    Then I am taken to "Gruyere: Home"

Gruyere.py

from lettuce import step, world
from nose.tools import assert_equal, assert_true
from selenium.webdriver.common.by import By

@step('I navigate to Gruyere')
def step_impl(step):
    world.driver.get("http://google-
gruyere.appspot.com/start")

@step('I choose to Agree & Start')
def step_impl(step):
    world.driver.find_element(By.LINK_TEXT, "Agree & Start ").click()

@step('I am taken to "([^"]*)"')
def step_impl(step, page_title):
    assert_equal(world.driver.title, page_title)

@step('I choose to Sign Up')
def step_impl(step):
    world.driver.find_element(By.LINK_TEXT, "Sign up ").click()

@step('I choose to Create Account with user name ".    ([^"]*)" and password "([^"]*)"')
def step_impl(step, user_name, password):
    world.driver.find_element(By.NAME, 
"uid").send_keys(user_name)
    world.driver.find_element(By.NAME, 
"pw").send_keys(password)
    world.driver.find_element(By.XPATH, 
"//input[@value='Create account']").click()

@step('I choose to Sign In')
def step_impl(step):
    world.driver.find_element(By.LINK_TEXT, "Sign in").click()

@step('I choose to Login with user name "([^"]*)" and     password "([^"]*)"')
def step_impl(step, user_name, password):
    world.driver.find_element(By.NAME, 
"uid").send_keys(user_name)
    world.driver.find_element(By.NAME, 
"pw").send_keys(password)
    world.driver.find_element(By.XPATH, 
"//input[@value='Login']").click()

Может кто знает, почему это неправильно и как это исправить? Полный учебник: https://the-creative-tester.github.io/Python-Security-Automation/

0 ответов

Другие вопросы по тегам