I can't connect to my site using Behat (but a browser is fine) - selenium

I've just started playing around with Behat, and I was loving it. Then I shut down my computer and went home for the day and when I came back, nothing worked for me any more. I've been trying to trouble-shoot this, but looks like the configurations vary so widely, I can't find anything that works for me. I'm getting the following error
Given I am on the homepage # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
Could not open connection: Curl error thrown for http POST to http://localhost:4444/wd/hub/session with params: {"desiredCapabilities":{"tags":["rio","PHP 5.5.9-1ubuntu4.9"],"browser":"firefox","version":"14","ignoreZoomSetting":false,"name":"Behat feature suite","browserName":"firefox"}}
The requested URL returned error: 500 Server Error (Behat\Mink\Exception\DriverException)
I've got my behat.yml file setup as such:
default:
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
extensions:
Behat\MinkExtension:
base_url: http://localhost:80/vic
goutte: ~
default_session: selenium2
browser_name: 'firefox'
selenium2:
capabilities: { "browser": "firefox", "version": "14"}
javascript_session: selenium2
Drupal\DrupalExtension:
blackbox: ~
drush:
root: /var/www/html/vic
api_driver: 'drupal'
drupal:
drupal_root: '/var/www/html/vic'
Like I said, this was previously working just fine. Now I don't know why it stopped. The error is weird to me too. the base url doesn't seem to be registering and I have no idea why it's pulling up port 4444 or going to the folder structure wd/hub/session.
Some background. I'm running this on my local machine on a local environment. I'm on a Linux box. The base url works for me in my browser, but Behat can't seem to reach it, and it's adding a weird port (should be 80), and path. It worked the other day, and nothing has changed other than a reboot (so I need to start up a service or something)?

Found the answer. Make sure selenium is running first.
java -jar selenium-server-standalone-2.45.0.jar (make sure your version is right)
Once it's running it'll give you connection info, make sure that matches in your behat.yml
extensions:
Behat\MinkExtension:
base_url: http://localhost:80
goutte: ~
javascript_session: selenium2
default_session: selenium2
browser_name: 'firefox'
selenium2:
capabilities: { "browser": "firefox", "version": "14"}
wd_host: http://127.0.0.1:4444/wd/hub
^^ do that by pointing the wd_host to the selenium instance

Related

Running selenium tests using Behat Drupal Extension inside DDEV containers

Problem: Get Behat Drupal Extension based testing working inside of ddev containers. This includes adding a separate selenium container to the existing configuration, being able to run Behat tests, and having the be able to reference the web host container.
Prerequisites: have a working ddev instance hosting Drupal. There are examples already to set that up, so I won't repeat that here.
The above task required the following additions:
selenium container: The container running selenium. I used the chrome standalone version. Add the following to your .ddev folder:
File: docker-compose.selenium.yml
version: '3.6'
services:
selenium:
container_name: ddev-${DDEV_SITENAME}-selenium
image: selenium/standalone-chrome-debug:3.13.0-argon
networks:
default:
aliases:
- web
The last bit is critical; the selenium container needs to know about the web container running the drupal instance to connect to it, but as it is a dependency of the web container, you can't use 'links'. You have to use the aliases approach, using the default network.
compose override: A file overriding the defaults for the web container to link the selenium container to it.
File: docker-compose.override.yml
version: '3.6'
services:
web:
depends_on:
- db
- selenium
links:
- db:db
- selenium:selenium
Behat configuration: The following Behat configuration for MinkExtension worked for me:
(modify file behat.yml)
default:
extensions:
"Behat\\MinkExtension":
goutte: null
base_url: 'http://web'
javascript_session: selenium2
selenium2:
browser: "chrome"
wd_host: http://selenium:4444/wd/hub
capabilities:
extra_capabilities:
idle-timeout: 50
base_url and wd_host entries were critical in getting this to work.
For more information on the last, see step 5 in the Behat Drupal Extension docs:
Configure your testing environment by creating a file called behat.yml with the following. Be sure that you point the base_url at the web site YOU intend to test. Do not include a trailing slash:
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Drupal\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://seven.l
Drupal\DrupalExtension:
blackbox: ~

Selenium doesn't start webdriver

versions
"nightwatch": "^0.9.16"
"chromedriver": "^2.30.1"
"selenium-server-standalone-jar": "^3.4.0"
I'm using nightwatch but that sh
I also tried with
I'm using nightwatch to run Selenium in this repo and I've tried with chrome and firefox drivers, no luck on either.
I have selenium standalone and chromedriver packages, and I know the path is right on nightwatch.conf.js:
const jar = require('selenium-server-standalone-jar')
console.log(jar.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar
const chromedriver = require('chromedriver')
console.log(chromedriver.path) // logs /home/goldylucks/apps/ci-workshop/node_modules/chromedriver/lib/chromedriver/chromedriver
'selenium': {
'start_process': true,
'server_path': jar.path,
'log_path': '',
'port': 4444,
'cli_args': {
'webdriver.chrome.driver': chromedriver.path,
'webdriver.ie.driver': '',
},
},
'test_settings': {
'chrome': {
'desiredCapabilities': {
'browserName': 'chrome',
'javascriptEnabled': true,
'acceptSslCerts': true,
},
},
yet when I run the test it times out and hangs:
$ yarn e2e:ui
yarn e2e:ui v0.24.6
$ nightwatch -e chrome
Starting selenium server... started - PID: 12936
[App E2e Ui] Test Suite
===========================
✖ Timed out while waiting for element <body> to be present for 5000 milliseconds. - expected "visible" but got: "not found"
at Object.before (/home/goldylucks/apps/ci-workshop/test/ui/app.e2e-ui.js:9:8)
I tried it with the following combinations:
1. with the express server which serves the app on another terminal
2. without the express server
3. each of the above with chromedriver manually started at another terminal (I really don't think it should matter and that I should do this, just wanted to be thorough ...)
running the chromedriver manually yields the following and hangs:
$ node_modules/chromedriver/lib/chromedriver/chromedriver
Starting ChromeDriver 2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5) on port 9515
Only local connections are allowed.
I also tried running with firefox and it didn't work, which leads me to believe the problem is deeper than the chromedriver, i.e. related to selenium interacting with nightwatch.
I recall this happening a while back. I think it was that a previous instance Selenium had not closed freed port 4444 when shutting down. Try shutting down selenium and restarting.
To do that, open the following webpage manually, in the browser of your choice.
http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer
Then try running the script again as normal.

Install ZombieDriver for Mink/Behat under Windows

The installation instructions at http://mink.behat.org/en/latest/drivers/zombie.html are (a) incomplete and (b) Linux only.
How can I install ZombieDriver on Windows?
Follow the instructions at http://mink.behat.org/en/latest/drivers/zombie.html and just skip this step: export NODE_PATH="/PATH/TO/NPM/node_modules"
Set up your behat.yml like this:
default:
# ...
extensions:
Behat\MinkExtension:
base_url: http://www.example.com/
default_session: zombie
javascript_session: zombie
zombie:
node_modules_path: 'C:\Users\<Username>\AppData\Roaming\npm\node_modules'
However, I'm not sure if this is the "right" or recommended way, but it works for me. I'm just posting this here cause I couldn't find any other resource on the web.

Getting started testing Javascript interactions with Drupal 7, Behat 3, Selenium2

I have been stuck on how to configure my Drupal 7 site to work with Behat to test Javascript interactions.
This is the setup I am starting with. If someone could help me modify my configuration to support testing Javascript I would greatly appreciate it.
Vagrant 1.8.1 running:
- Ubuntu 14.04.2 LTS
- PHP 5.6.22-1+donate.sury.org~trusty+1 (cli)
- Drupal 7.41
- Selenium: selenium-server-standalone-2.46.0.jar
I started Selenium using the following commands:
java -jar /opt/selenium/selenium-server-standalone.jar -role hub -port 4444
java -jar /opt/selenium/selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register
It looks like Selenium is running: lsof -i -n -P | grep 4444
php 2428 vagrant 6u IPv6 22327 0t0 TCP [::1]:46489->[::1]:4444 (CLOSE_WAIT)
composer.json
{
"require-dev": {
"drush/drush": "7.1.0",
"drupal/coder": "7.2.5",
"phpunit/php-timer": "dev-master",
"pear/Console_Color2": "0.1.2",
"behat/behat": "3.1.0",
"behat/mink": "1.7.1",
"behat/mink-extension": "2.2",
"behat/mink-goutte-driver": "1.2.1",
"behat/mink-selenium2-driver": "1.3.1",
"drupal/drupal-extension": "3.2.1"
},
"config": {
"bin-dir": "bin/"
}
}
behat.yml
# behat.yml
default:
autoload: [ %paths.base%/contexts ]
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://test.dev
Drupal\DrupalExtension:
blackbox: ~
suites:
default:
paths: [ %paths.base%/features ]
filters:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
contexts/FeatureContext.php
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
}
features/test.feature
Feature: Test DrupalContext
In order to prove the Drupal context using the blackbox driver is working properly
As a developer
I need to use the step definitions of this context
#javascript
Scenario: Test the ability to find a heading in a region
Given I am on the homepage
When I click "some link"
Then I should see the heading "Some heading"
When I run test.feature behat features/test.feature I get the following output. I do not know how to get the stack trace to output. If you can tell me how I will add that information to my post.
Feature: Test DrupalContext
In order to prove the Drupal context using the blackbox driver is working properly
As a developer
I need to use the step definitions of this context
#javascript
Scenario: Test the ability to find a heading in a region # features/test.feature:7
Given I am on the homepage # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
Could not open connection (Behat\Mink\Exception\DriverException)
When I click "some link" # Drupal\DrupalExtension\Context\MinkContext::assertClick()
Then I should see the heading "Some heading" # Drupal\DrupalExtension\Context\MinkContext::assertHeading()
Since you are testing a Drupal 7 site, I would recommend you to use the Drupal Extension that is provided by Behat. Looks like you have already required the necessary extension in your composer file. So no need to update the composer in this case.
However, you can use the 'drupal' driver or 'drush' driver here instead of 'blackbox', since they are much more powerful. If you have a local setup of the site, go ahead with the 'Drupal' driver. 'Drupal' driver is the strongest of the available API drivers.
Please follow the steps below to get your first scenario running:
Modify your behat.yml file as below:
Drupal\DrupalExtension:
api_driver: 'drupal'
drupal:
drupal_root: /path/to/docroot/
2. Modify your FeatureContext file, class file should extend DrupalContext, so that you can use all the ready-made step definitions that Drupal extension provides.
class FeatureContext extends DrupalContext implements SnippetAcceptingContext, Context {
In the command prompt, in your Behat parent directory, type the command:
bin/behat --dl
Don't forget to tag your scenarios or the entire feature file with #api
This would give you a list of all in-built Drupal based step definitions. Let me know how it goes.

Need help setting up Mink Extension for Behat

I am new to using the Mink Extension for Behat V3.0.15. The Mink version number is 1.7.0.
I have set up the extension using the following configuration on my behat.yml file
default:
extensions:
Behat\MinkExtension:
base_url: http://en.wikipedia.org
goutte: ~
I keep on getting this error..
[Symfony\Component\Yaml\Exception\ParseException]
Indentation problem at line 4 (near " base_url: http://en.wikipedia.org").
Any help would be really appreciated! Thanks!
I found out the issue. There was a space indenting issue . It was a space indenting issue. Here is the configuration settings that worked...
default:
extensions:
Behat\MinkExtension:
base_url: http://en.wikipedia.org
goutte: ~