@Spring_Way
QA junior

Kак поместить несколько тест кейсов в один скрипт правильно?

Всем добрый день,

На прокете стоит задача - одним скриптом проверить все отделы
Ниже пример - ошибка в том что тест крашится при выполнении

def test_select_ptoduct(self):

запускается браузер - и потом крашится - как правильно сделать,

-*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pytest
from selenium.webdriver.support.ui import Select
import os
import sys
import unittest
import json


base_url = ""
Screenshot = ""
driver = webdriver.Chrome(".\chromedriver")

def load_config(path):
    config_path = os.path.join(path, 'config.json')

    if not os.path.exists(config_path):
        print('Not found config.json in {}'.format(path))
        return

    with open(config_path, 'r') as fp:
        config = json.load(fp)

    return config

script_path = os.path.dirname(os.path.abspath('.\....'))

#print script_path


<b>class SmokeTestSuite(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome(".\chromedriver")
        self.driver.implicitly_wait(10)

    def test_navigate(self):
        driver = self.driver
        driver.get(base_url)
        driver.maximize_window()

        username = driver.find_element_by_id("username")
        password = driver.find_element_by_id("password")


        username.send_keys("username")
        password.send_keys("pass")
        driver.find_element_by_name("login").click()



    def test_select_product(self):

        driver.find_element_by_id("id1").click()
        Select(driver.find_element_by_id("id")).select_by_visible_text(
            "a1")

    def test_project_explore
        driver.find_element_by_link_text("project").click()
        driver.find_element_by_id("ab44").click()



  
    def tearDown(self):
        print "Smoke Test Suite is over"
        self.driver.quit()

def TestRunner(pathToConfig, Env):
    script_path = os.path.dirname(os.path.abspath(pathToConfig))
    config = load_config(script_path)
    global base_url

    base_url = config[Env]
    print config[Env]
    print ("Config parent folder: ", script_path)
    print ("ConfigURL: ", base_url)

    suite = unittest.TestSuite()
   
    # Invoke TestRunner
    dir = os.getcwd()
    now = datetime.datetime.now()
    fp = file('path+name' + str(now.strftime("%B-%d-%Y %H-%M-%S")) + '.html', 'wb')
    # runner = unittest.TextTestRunner(buf)       #DEBUG: this is the unittest baseline
    runner = HTMLTestRunner(
        stream=fp,
        title='   title  ' + base_url,
        verbosity=0,
        description='Smoke test suite'
    )
    runner.run(suite)
  • Вопрос задан
  • 449 просмотров
Решения вопроса 1
crazyzubr
@crazyzubr
Python backend-developer
В тесте забыли добавить строку driver = self.driver

То есть
def test_select_product(self):
    driver = self.driver
    driver.find_element_by_id("id1").click()
    Select(driver.find_element_by_id("id")).select_by_visible_text("a1")
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы