K
K
kis-kis2018-06-22 16:01:04
Python
kis-kis, 2018-06-22 16:01:04

Why doesn't the autotest start?

Hello.
Please help a novice autotester to understand his mistakes.
Maybe share useful links :-)
The address of the resource has been changed, there is no access to it from the outside.
The following code works :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Chrome()
#Получение даты от начала эпохи в секундах, вычитание/сложение секунд в сутках, перевод в указанный 
#формат даты и преобразование в string для заполнения промежутка времени в поиске
datefrom = str(time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(time.time() - 86400)))
datetill = str(time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(time.time() + 86400)))

def logIn():
    # driver.maximize_window()
    driver.get('http://127.0.0.1/Account/LogOn')
    input_field = driver.find_element_by_id('Login')
    input_field.send_keys('root')
    input_field = driver.find_element_by_id('Password')
    input_field.send_keys('root')
    time.sleep(1)
    input_field.send_keys(Keys.ENTER)
    time.sleep(1)
    driver.get('http://127.0.0.1/Admin/Tools')
    time.sleep(1)
    driver.get('http://127.0.0.1/Banners')
    input_field = driver.find_element_by_id('DateFrom')
    input_field.send_keys(datefrom)
    input_field = driver.find_element_by_id('DateTill')
    input_field.send_keys(datetill)
    input_field.send_keys(Keys.ENTER)

    if driver.find_element_by_xpath("//span[@class='objects']") == 0:
        report_to_file = open('C:\Баннеры_наличие.txt', 'w')
        report_to_file.write('Баннеры не обнаружены')
        report_to_file.close()
        print('Баннеры не обнаружены')
    else:
        report_to_file = open('C:\Баннеры_наличие.txt', 'w')
        report_to_file.write('Баннеры обнаружены')
        report_to_file.close()
        print('Баннеры обнаружены')

logIn()

The following is the code that doesn't work:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

class BannersSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()

    def logIn(self):
        driver.get('http://127.0.0.1/Account/LogOn')
        self.assertIn("Portal", self.driver.title)
        input_field = self.driver.find_element_by_id('Login')
        input_field.send_keys('root')
        input_field = self.driver.find_element_by_id('Password')
        input_field.send_keys('root')
        time.sleep(1)

    def existingBanners(self):
        datefrom = str(time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(time.time() - 86400)))
        datetill = str(time.strftime('%d.%m.%Y %H:%M:%S', time.localtime(time.time() + 86400)))
        self.driver.get('http://127.0.0.1/Admin/Tools')
        time.sleep(1)
        self.driver.get('http://127.0.0.1/Banners')
        input_field = self.driver.find_element_by_id('DateFrom')
        input_field.send_keys(datefrom)
        input_field = self.driver.find_element_by_id('DateTill')
        input_field.send_keys(datetill)
        input_field.send_keys(Keys.ENTER)
        assert "No banners found." not in self.driver.page_source

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()

In the second option, the console displays
Ran 0 tests in 0.000s

OK

Process finished with exit code 0
Empty test suite.

My task is to "overturn" the test execution if something is not found in the specified interval (for example, banners)
and write it to the test report, and not to .txt files, as in the first option.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery Glukhovtsev, 2018-07-23
@valera-glukhovtsev

For UNIT tests in python, you need to create a testable class. From it, the pythoscope "class name.py" command creates a test class, which describes the test methods.

D
Denis, 2019-02-03
@Norkotik

The name of the test does not contain the word test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question