Fixed logging

Signed-off-by: Anton Danchenko <ant.danchenko@gmail.com>
This commit is contained in:
yevh-berdnyk 2018-10-25 00:01:30 +03:00 committed by Anton Danchenko
parent 0ee07ca72c
commit f8343cc377
No known key found for this signature in database
GPG Key ID: C2D4819B698627E4
7 changed files with 68 additions and 34 deletions

View File

@ -1,5 +1,3 @@
import org.sikuli.script.SikulixForJython
from sikuli import *
from tests.base_test_case import BaseTestCase
from views.sign_in_view import SignInView
@ -20,9 +18,12 @@ class TestCreateAccount(BaseTestCase):
def test_create_account_proceed_with_enter(self):
sign_in = SignInView()
sign_in.create_account_button.click()
sign_in.create_password_input.input_value('123456' + Key.ENTER)
sign_in.confirm_password_input.input_value('123456' + Key.ENTER)
sign_in.username_input.input_value('test' + Key.ENTER)
sign_in.create_password_input.input_value('123456')
sign_in.press_enter()
sign_in.confirm_password_input.input_value('123456')
sign_in.press_enter()
sign_in.username_input.input_value('test')
sign_in.press_enter()
sign_in.home_button.find_element()
def test_create_account_go_back(self):
@ -31,12 +32,15 @@ class TestCreateAccount(BaseTestCase):
sign_in.create_password_input.find_element()
sign_in.back_button.click()
sign_in.create_account_button.click()
sign_in.create_password_input.input_value('123456' + Key.ENTER)
sign_in.create_password_input.input_value('123456')
sign_in.press_enter()
sign_in.confirm_password_input.find_element()
sign_in.back_button.click()
sign_in.create_password_input.find_element()
sign_in.create_password_input.input_value('123456' + Key.ENTER)
sign_in.confirm_password_input.input_value('123456' + Key.ENTER)
sign_in.create_password_input.input_value('123456')
sign_in.press_enter()
sign_in.confirm_password_input.input_value('123456')
sign_in.press_enter()
sign_in.username_input.find_element()
sign_in.back_button.verify_element_is_not_present()
@ -51,6 +55,7 @@ class TestCreateAccount(BaseTestCase):
profile.log_out_button.click()
sign_in.other_accounts_button.click()
sign_in.element_by_text('user_2').click()
sign_in.password_input.input_value('qwerty' + Key.ENTER)
sign_in.password_input.input_value('qwerty')
sign_in.press_enter()
sign_in.profile_button.click()
profile.find_text('user_2')

View File

@ -22,5 +22,5 @@ class TestProfile(BaseTestCase):
profile = sign_in.profile_button.click()
profile.element_by_text('Advanced settings').click()
s_names = profile.get_mail_servers_list()
profile.aa(s_names[0]).is_active()
profile.get_mail_server(s_names[0]).is_active()

View File

@ -1,6 +1,3 @@
import org.sikuli.script.SikulixForJython
from sikuli import *
from tests import base_user
from tests.base_test_case import BaseTestCase
from views.sign_in_view import SignInView
@ -11,8 +8,8 @@ class TestRecoverAccess(BaseTestCase):
def test_recover_access(self):
sign_in = SignInView()
sign_in.i_have_account_button.click()
sign_in.recovery_phrase_input.send_as_key_event(base_user['passphrase'])
sign_in.recover_password_input.send_as_key_event('123456')
sign_in.recovery_phrase_input.send_keys(base_user['passphrase'])
sign_in.recover_password_input.send_keys('123456')
sign_in.sign_in_button.click()
sign_in.home_button.find_element()
profile = sign_in.profile_button.click()
@ -22,8 +19,11 @@ class TestRecoverAccess(BaseTestCase):
def test_recover_access_proceed_with_enter(self):
sign_in = SignInView()
sign_in.i_have_account_button.click()
sign_in.recovery_phrase_input.send_as_key_event(base_user['passphrase'] + Key.TAB)
type('123456' + Key.ENTER)
sign_in.recovery_phrase_input.send_keys(base_user['passphrase'])
sign_in.press_tab()
sign_in.recover_password_input.verify_is_focused()
sign_in.recover_password_input.input_value('123456')
sign_in.press_enter()
sign_in.home_button.find_element()
def test_recover_access_go_back(self):

View File

@ -18,7 +18,9 @@ def pytest_addoption(parser):
def pytest_configure(config):
pass
import logging
logging.basicConfig(level=logging.INFO)
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):

View File

@ -1,6 +1,7 @@
import logging
import time
import pytest
import re
import org.sikuli.script.SikulixForJython
from sikuli import *
@ -9,22 +10,27 @@ from sikuli import *
class BaseElement(object):
def __init__(self, screenshot):
self.screenshot = screenshot
self.name = re.findall('([^\/]+)(?=.png)', self.screenshot)[0].replace('_', ' ').title()
def find_element(self):
def find_element(self, log=True):
if log:
logging.info('Find %s' % self.name)
try:
wait(self.screenshot, 10)
except FindFailed:
pytest.fail('%s was not found' % self.__class__.__name__)
pytest.fail('%s was not found' % self.name)
def click(self):
logging.info('Click %s' % self.__class__.__name__)
self.find_element()
def click(self, log=True):
if log:
logging.info('Click %s' % self.name)
self.find_element(log=False)
click(self.screenshot)
def verify_element_is_not_present(self):
logging.info('Verify: %s is not present' % self.name)
try:
wait(self.screenshot, 10)
pytest.fail('%s is displayed but not expected' % self.__class__.__name__)
pytest.fail('%s is displayed but not expected' % self.name)
except FindFailed:
pass
@ -32,15 +38,26 @@ class BaseElement(object):
class InputField(BaseElement):
def input_value(self, value):
self.click()
logging.info("%s field: set value '%s'" % (self.name, value))
self.click(log=False)
type(value)
def send_as_key_event(self, value):
self.click()
def send_keys(self, value):
logging.info("Type '%s' to %s field" % (value, self.name))
self.click(log=False)
for i in str(value):
type(i)
time.sleep(0.5)
def is_focused(self):
self.find_element(log=False)
return find(self.screenshot).getTarget() == Env.getMouseLocation()
def verify_is_focused(self):
logging.info('Verify %s is focused' % self.name)
if not self.is_focused():
pytest.fail('%s is not focused' % self.name)
class TextElement(object):
def __init__(self, text):

View File

@ -1,3 +1,4 @@
import logging
import org.sikuli.script.SikulixForJython
from sikuli import *
import os
@ -12,8 +13,8 @@ class ProfileButton(BaseElement):
def __init__(self):
super(ProfileButton, self).__init__(IMAGES_PATH + '/profile_button.png')
def click(self):
super(ProfileButton, self).click()
def click(self, log=True):
super(ProfileButton, self).click(log=log)
from views.profile_view import ProfileView
return ProfileView()
@ -27,6 +28,7 @@ class BaseView(object):
self.back_button = BaseElement(IMAGES_PATH + '/back_button.png')
def find_text(self, expected_text):
logging.info("Find text '%s'" % expected_text)
for _ in range(3):
current_text = text().encode('ascii', 'ignore').replace('\n', ' ')
if expected_text in current_text:
@ -38,3 +40,11 @@ class BaseView(object):
def element_by_text(self, text):
return TextElement(text)
def press_enter(self):
logging.info('Press Enter button')
type(Key.ENTER)
def press_tab(self):
logging.info('Press Tab button')
type(Key.TAB)

View File

@ -16,12 +16,12 @@ class CreateAccountButton(BaseElement):
def __init__(self):
super(CreateAccountButton, self).__init__(IMAGES_PATH + '/create_account.png')
def find_element(self):
def find_element(self, log=False):
try:
super(CreateAccountButton, self).find_element()
super(CreateAccountButton, self).find_element(log=log)
except Failed:
self.screenshot = IMAGES_PATH + '/create_new_account.png'
super(CreateAccountButton, self).find_element()
super(CreateAccountButton, self).find_element(log=log)
class SignInView(BaseView):
@ -53,8 +53,8 @@ class SignInView(BaseView):
def recover_access(self, passphrase):
self.i_have_account_button.click()
self.recovery_phrase_input.send_as_key_event(passphrase)
self.recover_password_input.send_as_key_event('123456')
self.recovery_phrase_input.send_keys(passphrase)
self.recover_password_input.send_keys('123456')
self.sign_in_button.click()
self.home_button.find_element()
return HomeView()