Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit df21fba

Browse files
author
Leonid Makarov
authored
Merge pull request #142 from blinkreaction/develop
Release 1.4.1
2 parents 397597a + 7f0028f commit df21fba

16 files changed

Lines changed: 264 additions & 21 deletions

‎CHANGELOG.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 1.4.1 (2016-07-01)
4+
5+
- Hotfixes
6+
- Addressed an issue with php5 vs php7 supervisord service name
7+
- Account that winpty executable was renamed in 0.3.0 to "winpty.exe"
8+
- Added ability to stop Drude system containers with dsh
9+
- Stop docker daemon before running prerequsite updates on Ubuntu to prevent client-server difference error
10+
- Documentation updates
11+
- Massive updates to [Behat docs](docs/behat.md)
12+
- PHPStorm integration
13+
- Use hosts's Selenium server and browsers
14+
- phpcs docs updates
15+
16+
317
## 1.4.0 (2016-06-10)
418

519
- dsh v1.20.0

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0
1+
1.4.1

‎bin/dsh‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
DSH_VERSION=1.20.0
3+
DSH_VERSION=1.20.3
44

55
# Console colors
66
red='\033[0;91m'
@@ -455,6 +455,23 @@ _stop_containers ()
455455
# stop all but system containers (--label "group=system")
456456
docker ps --format '{{.ID}} {{.Label "group"}}' | grep -v 'system' | xargs docker stop
457457
fi
458+
if [[ "$1" == "proxy" ]] ; then
459+
echo-green 'Stopping Drude HTTP/HTTPS reverse proxy service...'
460+
docker stop vhost-proxy
461+
return
462+
fi
463+
464+
if [[ "$1" == "dns" ]] ; then
465+
echo-green 'Stopping Drude DNS service...'
466+
docker stop dns
467+
return
468+
fi
469+
470+
if [[ "$1" == "ssh-agent" ]] ; then
471+
echo-green 'Stopping Drude ssh-agent service...'
472+
docker stop ssh-agent
473+
return
474+
fi
458475
docker_compose stop
459476
}
460477

@@ -701,7 +718,7 @@ up ()
701718
down ()
702719
{
703720
check_dsh_environment
704-
_stop_containers $@
721+
_stop_containers "$@"
705722
}
706723

707724
# Stop Vagrant box
@@ -914,16 +931,17 @@ install_ubuntu ()
914931
fi
915932

916933
echo-green "Installing Docker..."
917-
curl -sSL https://get.docker.com/ | sh && \
918-
sudo usermod -aG docker $(whoami) && \
934+
sudo service docker stop && \
935+
curl -sSL https://get.docker.com/ | sh && \
936+
sudo usermod -aG docker $(whoami)
919937
sudo docker version
920-
if_failed "Docker installation/upgrade failed."
938+
if_failed "Docker installation/upgrade has failed."
921939

922940
echo-green "Installing Docker Compose..."
923941
sudo curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && \
924942
sudo chmod +x /usr/local/bin/docker-compose && \
925943
docker-compose --version
926-
if_failed "Docker Compose installation/upgrade failed."
944+
if_failed "Docker Compose installation/upgrade has failed."
927945

928946
echo-green "Adding a subnet for Drude..."
929947
# Make sure we don't do this twice
@@ -1249,8 +1267,10 @@ _run ()
12491267
# Workaround - run docker exec via winpty (console.exe) to get a tty console in cygwin.
12501268
if is_binary_found 'console'; then
12511269
winpty_cmd='console'
1270+
elif is_binary_found 'winpty'; then
1271+
winpty_cmd='winpty'
12521272
else
1253-
echo-red 'Winpty (console.exe) binary missing.'
1273+
echo-red 'Winpty binary is missing.'
12541274
echo 'Run "dsh install prerequisites" to install it.'
12551275
exit 1
12561276
fi
@@ -1523,7 +1543,11 @@ _set_cli_uid ()
15231543
echo-green "Reseting permissions on /var/www..."
15241544
docker exec -u root $(get_container_id cli) chown -R docker:users /var/www
15251545
echo-green "Restarting php daemon..."
1526-
docker exec -u root $(get_container_id cli) supervisorctl restart php5-fpm
1546+
# TODO: Remove. This code is to support legacy cli image version, where php5-fpm service name was used.
1547+
local php_service='php-fpm';
1548+
local local res=$(docker exec $(get_container_id cli) grep "program:php5-fpm" /etc/supervisor/conf.d/supervisord.conf)
1549+
if [[ "$res" != '' ]]; then php_service='php5-fpm'; fi
1550+
docker exec -u root $(get_container_id cli) supervisorctl restart $php_service
15271551
else
15281552
echo-green "Container and host uids already match ($container_uid)."
15291553
fi

‎docs/behat.md‎

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Drude expects your Behat tests to be in `tests/behat` folder of the project repo
1010
> \_ composer.json
1111
> \_ composer.lock
1212
13-
See [drude-testing](https://github.com/blinkreaction/drude-testing) repo for a good working example. This repo is used for automated tests of Drude builds.
13+
See [Drupal 7 sample project](https://github.com/blinkreaction/drude-d7-testing) repo for a working example.
1414

1515
## Docker profile example
1616

@@ -52,3 +52,207 @@ Tests can be launched with `dsh` (Drude Shell):
5252
dsh behat
5353

5454
This will download composer dependencies and run behat with the docker profile.
55+
56+
## Behat (goutte-driver)
57+
58+
Basic configuration (see [behat.common.yml](https://github.com/blinkreaction/drude-d7-testing/blob/master/tests/behat/behat.common.yml)) uses goutte as the default driver. Goutte is a very basic browser emulator. It is much faster than real browsers, but also very limited. It can make HTTP requests, but does not parse CSS, execute JS or do any rendering.
59+
60+
Goutte can be used in many cases and does not require additional configuration/installation.
61+
62+
## Behat (selenium2-driver)
63+
64+
If your tests require javascript support, selenium2-driver should be used. You can set selenium2-driver as the default one.
65+
Selenium2 works with real browsers, using them as zombies for testing purposes. You get a standard, feature reach, real browser, with CSS styling, JS and AJAX execution - all supported out of the box.
66+
67+
The easiest way to enable Selenium support is to use stock Selenium docker images.
68+
To do this, update `docker-compose.yml` file in your project folder as follows.
69+
70+
```yml
71+
# selenium2 node
72+
# Uncomment the service definition section below and the link in the web service above to start using selenium2 driver for Behat tests requiring JS support.
73+
browser:
74+
hostname: browser
75+
image: selenium/standalone-chrome
76+
ports:
77+
- "4444"
78+
environment:
79+
- DOMAIN_NAME=drude-d7-testing.browser.docker
80+
```
81+
82+
You can also use Firefox image: `selenium/standalone-firefox`
83+
84+
After updating `docker-compose.yml` you have to tell Behat to use Selenium.
85+
Add your selenium configuration in `behat.yml` (environment variable `DOMAIN_NAME` is used as `selenium2 wd_host`).
86+
87+
Example:
88+
89+
```yml
90+
# Docker profile.
91+
# For use inside the CLI container in Drude.
92+
docker:
93+
extensions:
94+
Behat\MinkExtension:
95+
# URL of the site when accessed inside Drude.
96+
base_url: http://drupal7.drude
97+
selenium2:
98+
wd_host: http://drude3-d7-testing.browser.docker:4444/wd/hub
99+
# Stick with chrome by default. It's 2x faster than firefox or phantomjs (your results may vary).
100+
browser_name: chrome
101+
Drupal\DrupalExtension:
102+
drupal:
103+
# Site docroot inside Drude.
104+
drupal_root: /var/www/docroot
105+
drush:
106+
# Site docroot inside Drude.
107+
root: /var/www/docroot
108+
```
109+
110+
## Behat (selenium2-driver) - using VNC
111+
112+
If you use Selenium with a browser in a container, you can receive test screenshots but you cannot see the browser itself. Sometimes it is very useful to watch tests running in the browser (e.g. when you are creating a new test and want to see how it performs).
113+
In such cases [VNC](https://en.wikipedia.org/wiki/Virtual_Network_Computing) can be used.
114+
115+
1. Install VNC client on your computer (there are many version for all platforms).
116+
2. Update `docker-compose.yml` file in your project folder:
117+
118+
```yml
119+
# selenium2 node
120+
# Uncomment the service definition section below and the link in the web service above to start using selenium2 driver for Behat tests requiring JS support.
121+
browser:
122+
hostname: browser
123+
image: selenium/standalone-chrome-debug
124+
ports:
125+
- "4444"
126+
- "5900:5900"
127+
environment:
128+
- DOMAIN_NAME=drude-d7-testing.browser.docker
129+
```
130+
You have to use `selenium/standalone-chrome-debug` or `selenium/standalone-firefox-debug` images. They both include a VNC server.
131+
Use `localhost:5900` as the host and `secret` as the password in your VNC client.
132+
Now if you connect with the VNC client and run behat test, you will be able to see tests running in the browser inside the container.
133+
134+
Note: If you are working with several project concurrently, it is a good idea to have a separate port per project (e.g. `5901:5900`, `5902:5900`, etc.)
135+
136+
## Integration with PhpStorm
137+
138+
It is possible to connect PhpStorm with the `cli` container and run behat tests from within PhpStorm.
139+
PhpStorm uses ssh to connect to and use remote interpreters and tools.
140+
141+
1. Add the following line in `docker-compose.yml` to expose ssh-server in the `cli`container:
142+
143+
```yml
144+
cli:
145+
...
146+
ports:
147+
- "2221:22"
148+
...
149+
```
150+
2. Update container configuration with `dsh up`.
151+
3. You should now be able to connect to the `cli` container via ssh. Use username `docker` and pasword `docker`:
152+
153+
```
154+
ssh docker@localhost -p 2223
155+
```
156+
157+
Note: If you are working with several project concurrently, it is a good idea to have a separate port per project (e.g. `2222:22`, `2223:22`, etc.)
158+
159+
### Add new deployment server
160+
161+
Open settings (menu item *File->Settings...*). In the opened window on the left side select item *Build, Execution, Deployment->Deployment*:
162+
163+
![](img/behat-phpstorm-deployment-configure.png)
164+
165+
Create new SFTP connection and fill-out the form. Don't forget to fill-out *Web server root URL*.
166+
Press *Test SFTP connection...* button and if everything is ok, you will see that test is successful.
167+
168+
On the second tab you should to check and correct mapping:
169+
170+
![](img/behat-phpstorm-deployment-configure-mapping.png)
171+
172+
Local path is path to your project on the host machine. Deployment path is `/var/www`
173+
174+
### Add a new PHP interpreter
175+
176+
Open settings (menu item *File->Settings...*). In the opened window on the left side select item *Languages & Frameworks->PHP*:
177+
178+
![](img/behat-phpstorm-PHP-configuration.png)
179+
180+
To add a new interpreter click on **...** button on *Interpreter:* line.
181+
182+
![](img/behat-phpstorm-PHP-configuration-deployment.png)
183+
184+
In the opened window add a new interpreter and choose **Deployment configuration** option and deployment server from select list (it should be server from previous step).
185+
186+
### Add Behat interpreter configuration
187+
188+
Open settings (menu item *File->Settings...*). In the opened window on the left side select item *Languages & Frameworks->PHP->Behat*:
189+
190+
![](img/behat-phpstorm-PHP-Behat-configuration.png)
191+
192+
Add a new PHP interpreter for Behat (it should be the interpreter from previous step).
193+
194+
Path to Behat is the path in the `cli` container - ``/var/www/tests/behat/bin/behat`
195+
196+
Default configuration file: `/var/www/tests/behat/behat.yml`
197+
198+
Check that your `behat.yml` contains `wd_host` for selenium in `Behat\MinkExtension` part:
199+
200+
![](img/behat-behat-yml.png)
201+
202+
It should be the same as in `behat.common.yml` for `docker` part.
203+
204+
### Add Behat debug configuration
205+
206+
Open *Run/Debug Configurations* (menu item *Run->Edit Configurations...*). In the opened window on the left side add new Behat configuration:
207+
208+
![](img/behat-run-debug-configuration.png)
209+
210+
Choose Test Runner option *Defined in the configuration file*.
211+
212+
### Run tests
213+
214+
On the PhpStorm panel choose Behat debug configuration and run it:
215+
216+
![](img/behat-run-tests.png)
217+
218+
If everything is ok, you will see a window with tests result (all tests are run in this case):
219+
220+
![](img/behat-run-window.png)
221+
222+
You can re-run any scenario from this window. If you click on scenario or test, PhpStorm will open window with this scenario/test.
223+
224+
You can also open folder with Behat features (`tests/behat/features` directory in your project) and
225+
run any feature tests by right clicking on it and choosing **Run 'feature-name'** option.
226+
227+
![](img/behat-test-features.png)
228+
229+
## Using host selenium2-driver
230+
231+
You can use selenium from your host machine instead of the selenium in a container.
232+
233+
Selenium Standalone Server is available [here](http://www.seleniumhq.org/download/).
234+
WebDriver for Chrome is available [here](https://sites.google.com/a/chromium.org/chromedriver/downloads).
235+
236+
Run selenium with Chrome webdriver:
237+
238+
> java -jar selenium-server-standalone-2.53.0.jar -Dwebdriver.chrome.driver=/path/to/webdriver/chromedriver
239+
240+
By default it is running on port `4444`, which can be verified by openning `http://localhost:4444/wd/hub/static/resource/hub.html` in a browser.
241+
242+
Update `behat.yml` (set `wd_host` to point to the host machine):
243+
244+
```yml
245+
# Local overrides to the default profile
246+
default:
247+
extensions:
248+
Behat\MinkExtension:
249+
# URL of the site when accessed locally.
250+
base_url: http://drupal7.drude
251+
# Configure browser to be used. Browser must be available on wd_host.
252+
browser_name: chrome
253+
selenium2:
254+
wd_host: http://192.168.10.1:4444/wd/hub/static/resource/hub
255+
...
256+
```
257+
258+
`192.168.10.1` is your machine's IP in Drude subnet.

‎docs/img/behat-behat-yml.png‎

21.2 KB
Loading
76.3 KB
Loading
95.6 KB
Loading
59.8 KB
Loading
48.8 KB
Loading
74.9 KB
Loading

0 commit comments

Comments
 (0)