-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingBot.py
More file actions
46 lines (39 loc) · 1.28 KB
/
TestingBot.py
File metadata and controls
46 lines (39 loc) · 1.28 KB
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
import os
import requests
from appium import webdriver
from appium.webdriver.client_config import AppiumClientConfig
from robot.libraries.BuiltIn import BuiltIn
HUB_URL = "https://hub.testingbot.com/wd/hub"
API_URL = "https://api.testingbot.com/v1/tests/{session_id}"
def _credentials():
key = os.environ.get("TB_KEY")
secret = os.environ.get("TB_SECRET")
if not key or not secret:
raise RuntimeError("TB_KEY and TB_SECRET environment variables must be set")
return key, secret
def open_testingbot_app(options):
key, secret = _credentials()
client_config = AppiumClientConfig(
remote_server_addr=HUB_URL,
username=key,
password=secret,
)
driver = webdriver.Remote(
command_executor=HUB_URL,
options=options,
client_config=client_config,
)
appium = BuiltIn().get_library_instance("AppiumLibrary")
appium._cache.register(driver, alias="testingbot")
def report_testingbot_status(name, status):
key, secret = _credentials()
appium = BuiltIn().get_library_instance("AppiumLibrary")
session_id = appium._current_application().session_id
payload = {"test[name]": name, "test[success]": int(status == "PASS")}
response = requests.put(
API_URL.format(session_id=session_id),
data=payload,
auth=(key, secret),
timeout=30,
)
assert response.status_code == 200, response.text