O
O
Olga Belova2018-04-25 23:29:15
Python
Olga Belova, 2018-04-25 23:29:15

How to put several test cases in one script correctly?

Good afternoon everyone, The
task is on the project - to check all departments with
one script

-*- 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)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2018-04-26
@Spring_Way

In the test, they forgot to add the line driver = self.driver
That is

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")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question