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 tests.base_test_case import BaseTestCase
from views.sign_in_view import SignInView from views.sign_in_view import SignInView
@ -20,9 +18,12 @@ class TestCreateAccount(BaseTestCase):
def test_create_account_proceed_with_enter(self): def test_create_account_proceed_with_enter(self):
sign_in = SignInView() sign_in = SignInView()
sign_in.create_account_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.confirm_password_input.input_value('123456' + Key.ENTER) sign_in.press_enter()
sign_in.username_input.input_value('test' + Key.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() sign_in.home_button.find_element()
def test_create_account_go_back(self): def test_create_account_go_back(self):
@ -31,12 +32,15 @@ class TestCreateAccount(BaseTestCase):
sign_in.create_password_input.find_element() sign_in.create_password_input.find_element()
sign_in.back_button.click() sign_in.back_button.click()
sign_in.create_account_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.confirm_password_input.find_element()
sign_in.back_button.click() sign_in.back_button.click()
sign_in.create_password_input.find_element() sign_in.create_password_input.find_element()
sign_in.create_password_input.input_value('123456' + Key.ENTER) sign_in.create_password_input.input_value('123456')
sign_in.confirm_password_input.input_value('123456' + Key.ENTER) sign_in.press_enter()
sign_in.confirm_password_input.input_value('123456')
sign_in.press_enter()
sign_in.username_input.find_element() sign_in.username_input.find_element()
sign_in.back_button.verify_element_is_not_present() sign_in.back_button.verify_element_is_not_present()
@ -51,6 +55,7 @@ class TestCreateAccount(BaseTestCase):
profile.log_out_button.click() profile.log_out_button.click()
sign_in.other_accounts_button.click() sign_in.other_accounts_button.click()
sign_in.element_by_text('user_2').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() sign_in.profile_button.click()
profile.find_text('user_2') profile.find_text('user_2')

View File

@ -22,5 +22,5 @@ class TestProfile(BaseTestCase):
profile = sign_in.profile_button.click() profile = sign_in.profile_button.click()
profile.element_by_text('Advanced settings').click() profile.element_by_text('Advanced settings').click()
s_names = profile.get_mail_servers_list() 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 import base_user
from tests.base_test_case import BaseTestCase from tests.base_test_case import BaseTestCase
from views.sign_in_view import SignInView from views.sign_in_view import SignInView
@ -11,8 +8,8 @@ class TestRecoverAccess(BaseTestCase):
def test_recover_access(self): def test_recover_access(self):
sign_in = SignInView() sign_in = SignInView()
sign_in.i_have_account_button.click() sign_in.i_have_account_button.click()
sign_in.recovery_phrase_input.send_as_key_event(base_user['passphrase']) sign_in.recovery_phrase_input.send_keys(base_user['passphrase'])
sign_in.recover_password_input.send_as_key_event('123456') sign_in.recover_password_input.send_keys('123456')
sign_in.sign_in_button.click() sign_in.sign_in_button.click()
sign_in.home_button.find_element() sign_in.home_button.find_element()
profile = sign_in.profile_button.click() profile = sign_in.profile_button.click()
@ -22,8 +19,11 @@ class TestRecoverAccess(BaseTestCase):
def test_recover_access_proceed_with_enter(self): def test_recover_access_proceed_with_enter(self):
sign_in = SignInView() sign_in = SignInView()
sign_in.i_have_account_button.click() sign_in.i_have_account_button.click()
sign_in.recovery_phrase_input.send_as_key_event(base_user['passphrase'] + Key.TAB) sign_in.recovery_phrase_input.send_keys(base_user['passphrase'])
type('123456' + Key.ENTER) 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() sign_in.home_button.find_element()
def test_recover_access_go_back(self): def test_recover_access_go_back(self):

View File

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

View File

@ -1,6 +1,7 @@
import logging import logging
import time import time
import pytest import pytest
import re
import org.sikuli.script.SikulixForJython import org.sikuli.script.SikulixForJython
from sikuli import * from sikuli import *
@ -9,22 +10,27 @@ from sikuli import *
class BaseElement(object): class BaseElement(object):
def __init__(self, screenshot): def __init__(self, screenshot):
self.screenshot = 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: try:
wait(self.screenshot, 10) wait(self.screenshot, 10)
except FindFailed: except FindFailed:
pytest.fail('%s was not found' % self.__class__.__name__) pytest.fail('%s was not found' % self.name)
def click(self): def click(self, log=True):
logging.info('Click %s' % self.__class__.__name__) if log:
self.find_element() logging.info('Click %s' % self.name)
self.find_element(log=False)
click(self.screenshot) click(self.screenshot)
def verify_element_is_not_present(self): def verify_element_is_not_present(self):
logging.info('Verify: %s is not present' % self.name)
try: try:
wait(self.screenshot, 10) 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: except FindFailed:
pass pass
@ -32,15 +38,26 @@ class BaseElement(object):
class InputField(BaseElement): class InputField(BaseElement):
def input_value(self, value): def input_value(self, value):
self.click() logging.info("%s field: set value '%s'" % (self.name, value))
self.click(log=False)
type(value) type(value)
def send_as_key_event(self, value): def send_keys(self, value):
self.click() logging.info("Type '%s' to %s field" % (value, self.name))
self.click(log=False)
for i in str(value): for i in str(value):
type(i) type(i)
time.sleep(0.5) 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): class TextElement(object):
def __init__(self, text): def __init__(self, text):

View File

@ -1,3 +1,4 @@
import logging
import org.sikuli.script.SikulixForJython import org.sikuli.script.SikulixForJython
from sikuli import * from sikuli import *
import os import os
@ -12,8 +13,8 @@ class ProfileButton(BaseElement):
def __init__(self): def __init__(self):
super(ProfileButton, self).__init__(IMAGES_PATH + '/profile_button.png') super(ProfileButton, self).__init__(IMAGES_PATH + '/profile_button.png')
def click(self): def click(self, log=True):
super(ProfileButton, self).click() super(ProfileButton, self).click(log=log)
from views.profile_view import ProfileView from views.profile_view import ProfileView
return ProfileView() return ProfileView()
@ -27,6 +28,7 @@ class BaseView(object):
self.back_button = BaseElement(IMAGES_PATH + '/back_button.png') self.back_button = BaseElement(IMAGES_PATH + '/back_button.png')
def find_text(self, expected_text): def find_text(self, expected_text):
logging.info("Find text '%s'" % expected_text)
for _ in range(3): for _ in range(3):
current_text = text().encode('ascii', 'ignore').replace('\n', ' ') current_text = text().encode('ascii', 'ignore').replace('\n', ' ')
if expected_text in current_text: if expected_text in current_text:
@ -38,3 +40,11 @@ class BaseView(object):
def element_by_text(self, text): def element_by_text(self, text):
return TextElement(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): def __init__(self):
super(CreateAccountButton, self).__init__(IMAGES_PATH + '/create_account.png') super(CreateAccountButton, self).__init__(IMAGES_PATH + '/create_account.png')
def find_element(self): def find_element(self, log=False):
try: try:
super(CreateAccountButton, self).find_element() super(CreateAccountButton, self).find_element(log=log)
except Failed: except Failed:
self.screenshot = IMAGES_PATH + '/create_new_account.png' self.screenshot = IMAGES_PATH + '/create_new_account.png'
super(CreateAccountButton, self).find_element() super(CreateAccountButton, self).find_element(log=log)
class SignInView(BaseView): class SignInView(BaseView):
@ -53,8 +53,8 @@ class SignInView(BaseView):
def recover_access(self, passphrase): def recover_access(self, passphrase):
self.i_have_account_button.click() self.i_have_account_button.click()
self.recovery_phrase_input.send_as_key_event(passphrase) self.recovery_phrase_input.send_keys(passphrase)
self.recover_password_input.send_as_key_event('123456') self.recover_password_input.send_keys('123456')
self.sign_in_button.click() self.sign_in_button.click()
self.home_button.find_element() self.home_button.find_element()
return HomeView() return HomeView()