This repository was archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCBTContext.php
More file actions
81 lines (64 loc) · 2.56 KB
/
CBTContext.php
File metadata and controls
81 lines (64 loc) · 2.56 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
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
75
76
77
78
79
80
81
<?php
require 'vendor/autoload.php';
class CBTContext extends Behat\Behat\Context\BehatContext
{
protected $CONFIG;
protected static $driver;
protected static $url;
private static $api = null;
public function __construct($parameters)
{
$GLOBALS['CONFIG'] = $parameters["cbt"];
$GLOBALS['CBT_USERNAME'] = getenv('CBT_USERNAME');
if (!$GLOBALS['CBT_USERNAME'])
$GLOBALS['CBT_USERNAME'] = $GLOBALS['CONFIG']['user'];
$GLOBALS['CBT_AUTHKEY'] = getenv('CBT_AUTHKEY');
if (!$GLOBALS['CBT_AUTHKEY'])
$GLOBALS['CBT_AUTHKEY'] = $GLOBALS['CONFIG']['key'];
$GLOBALS['CBT_URL'] = getenv('CBT_URL');
if (!$GLOBALS['CBT_URL'])
$GLOBALS['CBT_URL'] = $GLOBALS['CONFIG']['base_url'];
self::$api = new CBT\Api($parameters['cbt']['user'], $parameters['cbt']['key']);
}
/** @BeforeFeature */
public static function setup()
{
$CONFIG = $GLOBALS["CONFIG"];
# Each parallel test we are running will contain
$test_run_id = getenv("TEST_RUN_ID") ? getenv("TEST_RUN_ID") : 0;
# build the webdriver hub URL (e.g. https://username:authkey@crossbrowsertesting.com:80/wd/hub)
$url = "https://".$GLOBALS["CBT_USERNAME"].":".$GLOBALS["CBT_AUTHKEY"]."@".$CONFIG["server"]."/wd/hub";
# get the capabilities for this test_run_id
# caps contains the os, browser, and resolution
$browserCaps = $CONFIG["browsers"][$test_run_id];
# pull in capabilities that we want applied to all tests
foreach ($CONFIG["capabilities"] as $capName => $capValue) {
if (!array_key_exists($capName, $browserCaps))
$browserCaps[$capName] = $capValue;
}
self::$driver = RemoteWebDriver::create($url, $browserCaps, 120000, 120000);
self::$url = $GLOBALS["CBT_URL"];
}
private static function scoreTest($status)
{
return self::$api->score(self::$driver->getSessionID(), $status);
}
/** @AfterFeature */
public static function tearDown(Behat\Behat\Event\FeatureEvent $scope)
{
/*
* getResult() - returns the resulting (highest)
* feature run code:
* 4 when the feature has failed steps,
* 3 when the feature has undefined steps,
* 2 when the feature has pending steps,
* 0 when all steps are passing.
*/
if ($scope->getResult() === 0) {
self::scoreTest('pass');
} else {
self::scoreTest('fail');
}
self::$driver->quit();
}
}