This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconftest.py
74 lines (58 loc) · 2.28 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest
import os
import requests
import json
import re
from appium import webdriver
import testobject
def update_job(session_id, result):
result_json = json.dumps({"passed": result})
requests.put(
'https://app.testobject.com/api/rest/v2/appium/session/' + session_id + '/test/',
headers = { 'Content-Type': 'application/json',},
data = '{"passed": true}'
)
#endpoint = 'https://app.testobject.com/api/rest/appium/v2/session/{}/test/'.format(session_id)
#requests.put(endpoint, data=result_json)
@pytest.yield_fixture(scope='function')
def driver(request):
SAUCE_USERNAME = os.environ['SAUCE_USERNAME']
SAUCE_ACCESS_KEY = os.environ['SAUCE_ACCESS_KEY']
caps = {
'appiumVersion': '1.9.1',
'browserName': '',
'platformName': 'iOS',
'platformVersion': '12.1.4',
'deviceOrientation':'portrait',
'phoneOnly': False,
'tabletOnly': False,
'privateDevicesOnly': False
}
rdc_key = os.environ['TESTOBJECT_API_KEY']
rdc_user = os.environ['TESTOBJECT_USERNAME']
caps['testobject_api_key'] = rdc_key
test_name = request.node.name
caps['name'] = test_name
rdc_api = testobject.TestObject(rdc_user, rdc_key)
sauce_url = "http://us1.appium.testobject.com/wd/hub"
browser = webdriver.Remote(sauce_url, desired_capabilities=caps)
# This is specifically for SauceLabs plugin.
# In case test fails after selenium session creation having this here will help track it down.
# creates one file per test non ideal but xdist is awful
if browser:
print("SauceOnDemandSessionID={} job-name={}\n".format(browser.session_id, test_name))
else:
raise WebDriverException("Never created!")
yield browser
rdc_api.watcher.report_test_result(browser.session_id, True)
browser.quit()
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
# this sets the result as a test attribute for Sauce Labs reporting.
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# set an report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)
return rep