added an ability to run Jenkins job manually against any apk

This commit is contained in:
Anton Danchenko 2017-11-13 12:49:45 +02:00
parent 040a0782e9
commit 190e841f32
6 changed files with 36 additions and 25 deletions

View File

@ -15,7 +15,8 @@ def start_threads(amount, func, *args):
class TestData(object):
def __init__(self):
self.name = None
self.test_name = None
self.apk_name = None
basic_user = {'password': "newuniquepassword12",
@ -41,4 +42,4 @@ transaction_users = {
},
}
tests_data = TestData()
test_data = TestData()

View File

@ -57,9 +57,10 @@ class AbstractTestCase:
@property
def capabilities_sauce_lab(self):
desired_caps = dict()
desired_caps['app'] = pytest.config.getoption('apk')
desired_caps['app'] = 'sauce-storage:' + test_data.apk_name
desired_caps['build'] = pytest.config.getoption('build')
desired_caps['name'] = tests_data.name
desired_caps['name'] = test_data.test_name
desired_caps['platformName'] = 'Android'
desired_caps['appiumVersion'] = '1.7.1'
desired_caps['platformVersion'] = '6.0'

View File

@ -1,5 +1,4 @@
from tests import tests_data
import time
from tests import test_data
import requests
import re
from datetime import datetime
@ -19,26 +18,28 @@ def get_latest_apk():
dates.sort(key=lambda date: datetime.strptime(date, "%d-%b-%Y %H:%M"), reverse=True)
return re.findall('>(.*k)</a>\s*%s' % dates[0], raw_data)[0]
latest_apk = get_latest_apk()
latest_nightly_apk = dict()
latest_nightly_apk['name'] = get_latest_apk()
latest_nightly_apk['url'] = storage + latest_nightly_apk['name']
def pytest_addoption(parser):
parser.addoption("--build",
action="store",
default='build_' + time.strftime('%Y_%m_%d_%H_%M'),
default='build_' + latest_nightly_apk['name'],
help="Specify build name")
parser.addoption('--apk',
action='store',
default='sauce-storage:' + latest_apk,
help='Please provide url or local path to apk')
default=latest_nightly_apk['url'],
help='Url or local path to apk')
parser.addoption('--env',
action='store',
default='sauce',
help='Please specify environment: local/sauce')
def pytest_runtest_setup(item):
tests_data.name = item.name + '_' + latest_apk
help='Specify environment: local/sauce')
parser.addoption('--log',
action='store',
default=False,
help='Display each test step in terminal as plain text: True/False')
def is_master(config):
@ -48,21 +49,31 @@ def is_master(config):
def is_uploaded():
stored_files = SauceClient(sauce_username, sauce_access_key).storage.get_stored_files()
for i in range(len(stored_files['files'])):
if stored_files['files'][i]['name'] == latest_apk:
if stored_files['files'][i]['name'] == test_data.apk_name:
return True
def pytest_configure(config):
if config.getoption('log'):
import logging
logging.basicConfig(level=logging.INFO)
test_data.apk_name = ([i for i in [i for i in config.getoption('apk').split('/')
if '.apk' in i]])[0]
if is_master(config) and config.getoption('env') == 'sauce':
if not is_uploaded():
response = requests.get(storage + latest_apk, stream=True)
response = requests.get(config.getoption('apk'), stream=True)
response.raise_for_status()
file = BytesIO(response.content)
del response
requests.post('http://saucelabs.com/rest/v1/storage/'
+ sauce_username + '/' + latest_apk + '?overwrite=true',
+ sauce_username + '/' + test_data.apk_name + '?overwrite=true',
auth=(sauce_username, sauce_access_key),
data=file,
headers={'Content-Type': 'application/octet-stream'})
def pytest_runtest_setup(item):
test_data.test_name = item.name + '_' + test_data.apk_name

View File

@ -4,7 +4,7 @@ from tests.basetestcase import SingleDeviceTestCase
from views.home import HomeView
from tests.preconditions import set_password_as_new_user, recover_access
from tests import transaction_users
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
@pytest.mark.all
@ -68,7 +68,7 @@ class TestTransactions(SingleDeviceTestCase):
chats.find_full_text('0.1')
try:
chats.find_full_text('Sent', 10)
except NoSuchElementException:
except TimeoutException:
chats.find_full_text('Delivered', 10)
if test == 'group_chat':
chats.find_full_text('to ' + transaction_users[recipient]['username'], 60)

View File

@ -122,7 +122,7 @@ class ConfirmPublicKeyButton(BaseButton):
def __init__(self, driver):
super(ConfirmPublicKeyButton, self).__init__(driver)
self.locator = \
self.Locator.accessibility_id('toolbar-action')
self.Locator.xpath_selector('(//android.view.ViewGroup[@content-desc="icon"])[2]')
class ChatMessageInput(BaseEditBox):

View File

@ -1,7 +1,5 @@
from views.base_view import BaseViewObject
from views.base_element import *
from tests import tests_data
class RequestPasswordIcon(BaseButton):