Answer the question
In order to leave comments, you need to log in
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()
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()
Ran 0 tests in 0.000s
OK
Process finished with exit code 0
Empty test suite.
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question