Skip to content

Commit 0938a7c

Browse files
authored
Merge pull request #389 from zebrunner/develop
3.0.2
2 parents 00fac1a + a0153c3 commit 0938a7c

File tree

8 files changed

+211
-112
lines changed

8 files changed

+211
-112
lines changed

README.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ Feel free to support the development with a [**donation**](https://www.paypal.co
4343
* update `roles/devices/vars/main.yml` file according to the obligatory/optional comments inside.
4444
> Register all whitelisted Android and iOS devices with their udids!
4545
* Run ansible-playbook script to download the required components and set up udev rules:
46-
```
47-
ansible-playbook -vvv -i hosts devices.yml
46+
```bash
47+
./zebrunner.sh ansible
4848
```
4949
> To reregister the devices list only, you can use the following command:
50-
```
51-
ansible-playbook -vvv -i hosts devices.yml --tag registerDevices
50+
```bash
51+
./zebrunner.sh ansible devices
5252
```
5353
> To provide extra arguments including sudo permissions, you can use the below command:
54-
```
55-
ansible-playbook -vvv -i hosts --user=USERNAME --extra-vars "ansible_sudo_pass=PSWD" devices.yml
54+
```bash
55+
./zebrunner.sh ansible --user=USERNAME --extra-vars "ansible_sudo_pass=PSWD"
5656
```
5757
* Devices management script is deployed to /usr/local/bin/zebrunner-farm.
5858
* Udev rules with whitelisted devices are in /etc/udev/rules.d/90_mcloud.rules.
@@ -67,16 +67,16 @@ Feel free to support the development with a [**donation**](https://www.paypal.co
6767
> Register all whitelisted iOS devices (phones, tablets or TVes) with their udids!
6868
> Important! Only iOS devices supported on MacOS!
6969
* Run ansible-playbook script to download the required components and set up udev rules:
70-
```
71-
ansible-playbook -vvv -i hosts mac-devices.yml
70+
```bash
71+
./zebrunner.sh ansible
7272
```
7373
> To reregister the devices list only, you can use the following command:
74-
```
75-
ansible-playbook -vvv -i hosts mac-devices.yml --tag registerDevices
74+
```bash
75+
./zebrunner.sh ansible devices
7676
```
7777
> To provide extra arguments including sudo permissions, you can use the below command:
78-
```
79-
ansible-playbook -vvv -i hosts --user=USERNAME --extra-vars "ansible_sudo_pass=PSWD" mac-devices.yml
78+
```bash
79+
./zebrunner.sh ansible --user=USERNAME --extra-vars "ansible_sudo_pass=PSWD"
8080
```
8181
* Devices management script is deployed to /usr/local/bin/zebrunner-farm.
8282
* Whitelisted devices properties are in /usr/local/bin/mcloud-devices.txt.
@@ -107,19 +107,23 @@ Feel free to support the development with a [**donation**](https://www.paypal.co
107107

108108
You need an Apple Developer account to sign in and build **WebDriverAgent**.
109109

110-
1. Open **WebDriverAgent.xcodeproj** in Xcode.
111-
2. Ensure a team is selected before building the application. To do this, go to *Targets* and select each target (one at a time). There should be a field for assigning team certificates to the target.
112-
3. Remove your **WebDriverAgent** folder from *DerivedData* and run *Clean build folder* (just in case).
113-
4. Build the application by selecting the *WebDriverAgentRunner* target and build for *Generic iOS Device*. Run *Product -> Build for testing*. This will create a *Products/Debug-iphoneos* in the specified project directory.
110+
1. Clone **WebDriverAgent** from source you prefer. We recommend our [forked repository](https://github.com/zebrunner/WebDriverAgent) with performance improvements.
111+
```bash
112+
git clone https://github.com/zebrunner/WebDriverAgent.git
113+
```
114+
2. Open **WebDriverAgent.xcodeproj** in Xcode.
115+
3. Ensure a team is selected before building the application. To do this, go to *Targets* and select each target (one at a time). There should be a field for assigning team certificates to the target.
116+
4. Remove your **WebDriverAgent** folder from *DerivedData* and run *Clean build folder* (just in case).
117+
5. Build the application by selecting the *WebDriverAgentRunner* target and build for *Generic iOS Device*. Run *Product -> Build for testing*. This will create a *Products/Debug-iphoneos* in the specified project directory.
114118
*Example*: **/Users/$USER/Library/Developer/Xcode/DerivedData/WebDriverAgent-dzxbpamuepiwamhdbyvyfkbecyer/Build/Products/Debug-iphoneos**
115-
5. Go to the "Products/Debug-iphoneos" directory and run:
119+
6. Go to the "Products/Debug-iphoneos" directory and run:
116120
**mkdir Payload**
117-
6. Copy the WebDriverAgentRunner-Runner.app to the Payload directory:
121+
7. Copy the WebDriverAgentRunner-Runner.app to the Payload directory:
118122
**cp -r WebDriverAgentRunner-Runner.app Payload**
119-
7. Finally, zip up the project as an *.ipa file:
123+
8. Finally, zip up the project as an *.ipa file:
120124
**zip -r WebDriverAgent.ipa ./Payload**
121125
> Make sure to specify relative `./Payload` to archive only Payload folder content
122-
8. Share built ipa via WDA_FILE variable in roles/devices/vars/main.yml file.
126+
9. Share built ipa via WDA_FILE variable in roles/devices/vars/main.yml file.
123127
> to override WDA_FILE artifacts per each device use `wda_file` and `wda_bundleid` iOS device properties and re-execute ansible playbook.
124128
125129

@@ -152,6 +156,22 @@ Follow the below algorithm to identify any configuration issues with MCloud agen
152156
// artifacts uploader container:
153157
docker logs -f device-<Name>-<udid>-uploader
154158
```
159+
* If you have any problems running ansible:
160+
* Make sure you have sudo access and try to run ansible with sudo permissions.
161+
* Try to rub ansible commands manually (`<devices_file>` name is `mac-devices` on macOS or `devices` on Linux servers)
162+
163+
> To download the required components and set up udev rules:
164+
```
165+
ansible-playbook -vvv -i hosts <devices_file>.yml
166+
```
167+
> To reregister the devices list only, you can use the following command:
168+
```
169+
ansible-playbook -vvv -i hosts <devices_file>.yml --tag registerDevices
170+
```
171+
> To provide extra arguments including sudo permissions, you can use the below command:
172+
```
173+
ansible-playbook -vvv -i hosts --user=USERNAME --extra-vars "ansible_sudo_pass=PSWD" <devices_file>.yml
174+
```
155175

156176
## Documentation and free support
157177
* [Zebrunner PRO](https://zebrunner.com)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% for device in devices %}
2-
{{ device.name }}|{{ device.os }}|{{ device.id }}|{{ device.adb_port }}|{{ device.min_port }}|{{ device.max_port }}|{{ device.proxy_port | default('0') }}|{{ device.appium_port }}|{{ device.wireless | default('false') }}|{{ device.wda_file | default('/dev/null')}}|{{ device.wda_bundleid | default('com.facebook.WebDriverAgentRunner.xctrunner')}}|{{ device.server_proxy_port | default('0')}}
2+
{{ device.id }}|{{ device.os }}|{{ device.name }}|{{ device.location | default('') }}|{{ device.appium_port }}|{{ device.adb_port }}|{{ device.proxy_port | default('0') }}|{{ device.server_proxy_port | default('0') }}|{{ device.min_port }}|{{ device.max_port }}|{{ device.wireless | default('false') }}|{{ device.wda_file | default('/dev/null') }}|{{ device.wda_bundleid | default('com.facebook.WebDriverAgentRunner.xctrunner') }}
33
{% endfor %}

roles/devices/templates/zebrunner-farm

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,30 @@ function create_containers() {
4848
local platform_name=$(cat ${devices} | grep "$udid" | cut -d '|' -f 2)
4949
#echo "platform_name: $platform_name"
5050

51-
local device_adb_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 4)
52-
#echo "device_adb_port: $device_adb_port"
51+
local location=$(cat ${devices} | grep "$udid" | cut -d '|' -f 4)
52+
#echo "location: $location"
5353

54-
local stf_min_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 5)
55-
#echo "stf_min_port: $stf_min_port"
54+
local appium_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 5)
55+
#echo "appium_port: $appium_port"
5656

57-
local stf_max_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 6)
58-
#echo "stf_max_port: $stf_max_port"
57+
local device_adb_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 6)
58+
#echo "device_adb_port: $device_adb_port"
5959

6060
local proxy_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 7)
6161
#echo "proxy_port: $proxy_port"
6262

63-
local appium_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 8)
64-
#echo "appium_port: $appium_port"
63+
local server_proxy_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 8)
64+
#echo "server_proxy_port: $server_proxy_port"
65+
66+
local stf_min_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 9)
67+
#echo "stf_min_port: $stf_min_port"
6568

66-
local wireless=$(cat ${devices} | grep "$udid" | cut -d '|' -f 9)
69+
local stf_max_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 10)
70+
#echo "stf_max_port: $stf_max_port"
71+
72+
local wireless=$(cat ${devices} | grep "$udid" | cut -d '|' -f 11)
6773
#echo "wireless: $wireless"
6874

69-
local server_proxy_port=$(cat ${devices} | grep "$udid" | cut -d '|' -f 12)
70-
#echo "server_proxy_port: $server_proxy_port"
7175

7276
# without 'block_global=false' mitmproxy does not want to accept requests from devices
7377
# --set confdir allows to provide custom folder with CA Authority certificates
@@ -150,7 +154,7 @@ function create_containers() {
150154
-e STF_PROVIDER_DEVICE_NAME="${device_name}" \
151155
-e DEVICE_UDID="$STF_DEVICE_UDID" \
152156
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
153-
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
157+
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}${location:+_$location}" \
154158
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
155159
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
156160
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
@@ -219,7 +223,7 @@ function create_containers() {
219223

220224
#TODO: comment echoing wda related detailes before release
221225
local wdaIpaPath={{ WDA_FILE }}
222-
local deviceWdaIpaPath=$(cat ${devices} | grep "$udid" | cut -d '|' -f 10)
226+
local deviceWdaIpaPath=$(cat ${devices} | grep "$udid" | cut -d '|' -f 12)
223227
if [ ! -z $deviceWdaIpaPath ] && [ ! "$deviceWdaIpaPath" == "/dev/null" ]; then
224228
wdaIpaPath=$deviceWdaIpaPath
225229
fi
@@ -230,7 +234,7 @@ function create_containers() {
230234
echo "wdaIpaPath: $wdaIpaPath"
231235

232236
local wdaBundleId={{ WDA_BUNDLEID }}
233-
local deviceWdaBundleId=$(cat ${devices} | grep "$udid" | cut -d '|' -f 11)
237+
local deviceWdaBundleId=$(cat ${devices} | grep "$udid" | cut -d '|' -f 13)
234238
if [ ! -z $deviceWdaBundleId ]; then
235239
wdaBundleId=$deviceWdaBundleId
236240
fi
@@ -277,7 +281,7 @@ function create_containers() {
277281
-e STF_PROVIDER_DEVICE_NAME="${device_name}" \
278282
-e DEVICE_UDID="${udid}" \
279283
-e STF_PROVIDER_HOST={{ STF_PROVIDER_HOST }} \
280-
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}" \
284+
-e STF_PROVIDER_NAME="{{ STF_PROVIDER_NAME }}${location:+_$location}" \
281285
-e STF_PROVIDER_MIN_PORT=$stf_min_port \
282286
-e STF_PROVIDER_MAX_PORT=$stf_max_port \
283287
-p $stf_min_port-$stf_max_port:$stf_min_port-$stf_max_port \
@@ -348,9 +352,9 @@ function stop() {
348352
# if $device is empty do stop for all connected devices otherwise stop only filtered
349353
if [ ! -z $filter_device ] && [ "$filter_device" != "ios" ] && [ "$filter_device" != "android" ]; then
350354
echo stopping containers for $filter_device...
351-
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
355+
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
352356
local device_name_underscored=${device_name// /_}
353-
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
357+
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
354358

355359
if [ -z "$device_name" ] || [ -z $udid ]; then
356360
echo_warning "Unable to find device by \"$filter_device\"!"
@@ -361,13 +365,13 @@ function stop() {
361365
else
362366
# as no device filter provided continue with stopping all device containers
363367
while read -r line; do
364-
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
368+
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
365369
#echo "device_name: $device_name"
366370
local device_name_underscored=${device_name// /_}
367371

368-
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
372+
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
369373
#echo "udid: $udid"
370-
local wireless=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 9)
374+
local wireless=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 11)
371375

372376
if [ -L "/dev/device-${device_name}-${udid}" ] || [ "$wireless" == "True" ]; then
373377
stop_containers ${device_name_underscored} ${udid}
@@ -402,9 +406,9 @@ function down() {
402406
# if $device is empty do rm for all connected devices otherwise rm only filtered
403407
if [ ! -z $filter_device ] && [ "$filter_device" != "ios" ] && [ "$filter_device" != "android" ]; then
404408
#echo removing containers for $filter_device...
405-
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
409+
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
406410
local device_name_underscored=${device_name// /_}
407-
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
411+
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
408412

409413
if [ -z "$device_name" ] || [ -z $udid ]; then
410414
echo_warning "Unable to find device by \"$filter_device\"!"
@@ -414,11 +418,11 @@ function down() {
414418
remove_containers ${device_name_underscored} ${udid}
415419
else
416420
while read -r line; do
417-
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
421+
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
418422
#echo "device_name: $device_name"
419423
local device_name_underscored=${device_name// /_}
420424

421-
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
425+
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
422426
#echo "udid: $udid"
423427
remove_containers ${device_name_underscored} ${udid}
424428
done < ${devices}
@@ -529,7 +533,7 @@ function verify_containers() {
529533
local udid=$2
530534
#echo "udid: $udid"
531535

532-
local wireless=$(cat ${devices} | grep "$udid" | cut -d '|' -f 9)
536+
local wireless=$(cat ${devices} | grep "$udid" | cut -d '|' -f 11)
533537

534538
local container=device-$device-$udid
535539
if [ ! -L "/dev/$container" ] && [ "$wireless" != "True" ]; then
@@ -574,11 +578,11 @@ function verify_containers() {
574578
connectorRestarts="$(docker inspect --format='{{ '{{' }}.RestartCount{{ '}}' }}' $container-connector)"
575579
fi
576580

577-
echo -e ",Container,State,Status,Uptime,Restarts,
578-
,---------,---------,---------,---------,---------,
579-
,Connector,$connectorState,$connectorStatus,$connectorUptime,$connectorRestarts,
580-
,Appium,$appiumState,$appiumStatus,$appiumUptime,$appiumRestarts,
581-
,STF,$stfState,$stfStatus,$stfUptime,$stfRestarts," | column -t -s ',' -o ' | ' -L
581+
echo -e ",| Container,| State,| Status,| Uptime,| Restarts,|
582+
,| ---------,| ---------,| ---------,| ---------,| ---------,|
583+
,| Connector,| $connectorState,| $connectorStatus,| $connectorUptime,| $connectorRestarts,|
584+
,| Appium,| $appiumState,| $appiumStatus,| $appiumUptime,| $appiumRestarts,|
585+
,| STF,| $stfState,| $stfStatus,| $stfUptime,| $stfRestarts,|" | column -t -s ','
582586

583587
fi
584588
echo -e "==============================================================\n"
@@ -590,9 +594,9 @@ function start() {
590594

591595
# if $device is empty do start for all connected devices otherwise start only filtered
592596
if [ ! -z $filter_device ] && [ "$filter_device" != "ios" ] && [ "$filter_device" != "android" ]; then
593-
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
597+
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
594598
local device_name_underscored=${device_name// /_}
595-
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
599+
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
596600

597601
if [ -z "$device_name" ] || [ -z $udid ]; then
598602
echo_warning "Unable to find device by \"$filter_device\"!"
@@ -603,13 +607,13 @@ function start() {
603607
echo -e "\n-----------------------------------------------------------------"
604608
else
605609
while read -r line; do
606-
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
610+
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
607611
#echo "device_name: $device_name"
608612
local device_name_underscored=${device_name// /_}
609613

610-
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
614+
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
611615
#echo "udid: $udid"
612-
local wireless=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 9)
616+
local wireless=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 11)
613617
if [ -L "/dev/device-${device_name}-${udid}" ] || [ "$wireless" == "True" ]; then
614618
create_containers "${device_name}" "${udid}" "${device_name_underscored}" && start_containers "${device_name}" "${udid}" "${device_name_underscored}"
615619
echo -e "\n-----------------------------------------------------------------"
@@ -643,18 +647,18 @@ function status() {
643647

644648
# if $device is empty do start for all connected devices otherwise start only filtered
645649
if [ ! -z $filter_device ] && [ "$filter_device" != "ios" ] && [ "$filter_device" != "android" ]; then
646-
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
650+
local device_name=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
647651
#echo "device_name: $device_name"
648652
local device_name_underscored=${device_name// /_}
649-
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 3)
653+
local udid=$(cat ${devices} | grep "$filter_device" | cut -d '|' -f 1)
650654
#echo "udid: $udid"
651655
verify_containers "${device_name_underscored}" "${udid}"
652656
else
653657
while read -r line; do
654-
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
658+
local device_name=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
655659
#echo "device_name: $device_name"
656660
local device_name_underscored=${device_name// /_}
657-
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 3)
661+
local udid=$(echo ${line} | grep "$filter_device" | cut -d '|' -f 1)
658662
if [ -z $udid ]; then
659663
continue
660664
fi
@@ -680,15 +684,31 @@ function echo_help() {
680684
echo "
681685
Usage: zebrunner-farm [option]
682686
Arguments:
683-
status Status of MCloud Agent and each whitelisted device
684-
start [udid] Start devices containers or exact device by udid
685-
stop [udid] Stop and keep devices containers or exact device by udid
686-
restart [udid] Restart all devices containers or exact device by udid
687-
down [udid] Stop and remove devices containers"
687+
status Status of MCloud Agent and each whitelisted device
688+
start [udid] Start devices containers or exact device by udid
689+
stop [udid] Stop and keep devices containers or exact device by udid
690+
restart [udid] Restart all devices containers or exact device by udid
691+
down [udid] Stop and remove devices containers
692+
ansible ['devices'] Run ansible-playbook script with custom or predefined args"
688693
echo_telegram
689694
exit 0
690695
}
691696

697+
# IMPORTANT! In case of any changes please copy them in ./zebrunner.sh !
698+
function ansible() {
699+
if [[ "$1" == "" ]]; then
700+
arg="devices.yml"
701+
elif [[ "$1" == "devices" ]]; then
702+
arg="devices.yml --tag registerDevices"
703+
else
704+
arg="$@ devices.yml"
705+
fi
706+
707+
echo "ansible-playbook -vvv -i hosts $arg"
708+
echo "*******************************************************************"
709+
ansible-playbook -vvv -i hosts $arg
710+
}
711+
692712
#CONTAINERS=( `docker ps --format '{{ '{{' }}.Names{{ '}}' }}' | grep device | grep -v appium | cut -d '-' -f 2-` )
693713
#echo CONTAINERS: $CONTAINERS
694714

@@ -724,6 +744,9 @@ restart)
724744
down)
725745
down $2
726746
;;
747+
ansible)
748+
ansible "${@:2}"
749+
;;
727750
shutdown)
728751
shutdown
729752
;;

0 commit comments

Comments
 (0)