Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PL-32: Demo Functional tests using Behat. #16

Merged
merged 11 commits into from
Feb 6, 2020
9 changes: 5 additions & 4 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ default:
cache: ~
extensions:
Behat\MinkExtension:
goutte: ~
browser_name: 'chrome'
selenium2:
wd_host: "http://127.0.0.1:8643/wd/hub"
wd_host: "http://127.0.0.1:4444/wd/hub"
capabilities: { "browserName": "chrome", "browser": "chrome", "version": "72", 'chrome': {'switches':['--no-sandbox', '--headless']}}
javascript_session: selenium2
base_url: http://federated-search-demo.local
base_url: http://d8.fs-demo.local
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drupal'
drupal:
drupal_root: 'web'
drupal_root: 'web/d8/docroot'
text:
username_field: 'name'
password_field: 'pass'
Expand Down
13 changes: 13 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@
</target>


<!-- Target: start-selenium -->
<target name="start-selenium">
<exec command='java -jar -Dwebdriver.chrome.driver="/usr/local/share/chromedriver/chromedriver" /usr/local/share/selenium/selenium-server-standalone.jar >/dev/null 2>&amp;1 &amp;' dir="/home" />
</target>


<!-- Target: behat -->
<target name="behat">
<phingcall target="start-selenium" />
<exec command='vendor/bin/behat --tags=javascript' logoutput="true" checkreturn="true" />
</target>


<!-- Default target: list -->
<target name="list" hidden="true">
<exec command="phing -q -f ${phing.file} -l" passthru="true"/>
Expand Down
35 changes: 35 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,39 @@ public function __construct()
{
}

/**
* @When I wait for :arg1 second
*/
public function iWaitForSecond($arg1)
{
sleep($arg1);
}

/**
* @Given I click the :arg1 element
*
* See https://stackoverflow.com/questions/33649518/how-can-i-click-a-span-in-behat.
*/
public function iClickTheElement($selector)
{
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);

if (empty($element)) {
throw new Exception("No html element found for the selector ('$selector')");
}

$element->click();
}

/**
* @BeforeStep
*
* Size the window so that all the elements are visible.
*/
public function beforeStep()
{
$this->getSession()->resizeWindow(1920, 1080, 'current');
}

}
12 changes: 12 additions & 0 deletions features/drupal-7-search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@javascript
Feature: Drupal 7 search
As a site visitor
I want to search the Drupal 7 sites
So that I can content from other sites

Scenario: Search for "terrier"
Given I visit "/search-app?search=terrier"
When I wait for "1" second
Then I should see the text "English Terrier"
And I should see the text "Drupal 7 - Federated Search"
And I should see the text "Federated Search Domain 3"
42 changes: 42 additions & 0 deletions features/drupal-8-search-filters.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@javascript
Feature: Federated search filers
As a site visitor
I want to search the federated sites
And I want to filter my results
So that I can find relevant information more quickly

Scenario: Filter by type
Given I visit "/search-app?search=terrier"
And I wait for "1" second
# When I expand the "Type" filter
When I click the "#solr-list-facet-ss_federated_type" element
# When I select the "Article" filter
And I check "Article"
Then I should see the text "Jack Russell Terrier"
And I should see the text "English Terrier"
And I should see the text "Irish Terrier"

Scenario: Filter by site - D8 single
Given I visit "/search-app?search=terrier"
And I wait for "1" second
# When I expand the "Site Name" filter
When I click the "#solr-list-facet-sm_site_name" element
# When I select the "Federated Search Drupal 8" filter
And I check "Federated Search Drupal 8"
Then I should see the text "Federated Search Drupal 8"
And I should see the text "Jack Russell Terrier"
And I should see the text "Boston Terrier"
And I should not see the text "Drupal 7 - Federated Search"
And I should not see the text "Federated Search Domain 3"

Scenario: Filter by site - D8 domain
Given I visit "/search-app?search=terrier"
And I wait for "1" second
# When I expand the "Site Name" filter
When I click the "#solr-list-facet-sm_site_name" element
# When I select the "Federated Search Domain 3" filter
And I check "Federated Search Domain 3"
Then I should see the text "Federated Search Domain 3"
And I should see the text "Norfolk Terrier"
And I should see the text "Federated Search Drupal 8"
And I should not see the text "Drupal 7 - Federated Search"
11 changes: 11 additions & 0 deletions features/drupal-8-search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@javascript
Feature: Drupal 8 search
As a site visitor
I want to search the Drupal 8 sites
So that I can read recipes

Scenario: Search for "terrier"
Given I visit "/search-app?search=terrier"
And I wait for "1" second
Then I should see the text "Jack Russell Terrier"
And I should see the text "Federated Search Drupal 8"
1 change: 1 addition & 0 deletions provisioning/federated-search-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@
- { role: mysql }
- { role: apache }
- { role: solr-cors }
- { role: selenium-webdriver }
- { role: drush }
44 changes: 44 additions & 0 deletions provisioning/roles/selenium-webdriver/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Create directory for Selenium
become: yes
file:
path: /usr/local/share/selenium
state: directory

- name: Selenium
become: yes
get_url:
url: https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
dest: /usr/local/share/selenium/selenium-server-standalone.jar

- name: Create directory for Chromedriver
become: yes
file:
path: /usr/local/share/chromedriver
state: directory

- name: Download Chromedriver
become: yes
unarchive:
remote_src: yes
src: https://chromedriver.storage.googleapis.com/72.0.3626.7/chromedriver_linux64.zip
dest: /usr/local/share/chromedriver
mode: "+x"

- name: "Install Chrome - Ensure Google linux signing key present"
become: yes
apt_key:
url: https://dl-ssl.google.com/linux/linux_signing_key.pub

- name: "Install Chrome - Ensure Google Chrome repo present"
become: yes
apt_repository:
repo: "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
filename: "google-chrome"
state: present
update_cache: yes

- name: Install Chrome
become: yes
apt:
name: google-chrome-stable