diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..197c4d5c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.0 diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..d4fb7ead --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gem 'rspec' +gem 'selenium-webdriver' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..4dab3360 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,36 @@ +GEM + remote: https://rubygems.org/ + specs: + childprocess (0.6.2) + ffi (~> 1.0, >= 1.0.11) + diff-lcs (1.3) + ffi (1.9.18) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + rubyzip (1.2.1) + selenium-webdriver (3.3.0) + childprocess (~> 0.5) + rubyzip (~> 1.0) + websocket (~> 1.0) + websocket (1.2.4) + +PLATFORMS + ruby + +DEPENDENCIES + rspec + selenium-webdriver + +BUNDLED WITH + 1.13.6 diff --git a/circle.yml b/circle.yml new file mode 100644 index 00000000..449f2644 --- /dev/null +++ b/circle.yml @@ -0,0 +1,15 @@ +machine: + services: + - docker + +test: + override: + - docker build -t leonstafford/wordpress-static-html-plugin:latest . + - docker run --name devmysql -e MYSQL_ROOT_PASSWORD=banana -d mariadb + - docker run --name plugindevwp --link devmysql:mysql -p 8080:80 -d -v $(pwd):/app leonstafford/wordpress-static-html-plugin + - docker exec plugindevwp sh /post_launch.sh # leaves site running + - echo 'launching selenium server container' + - docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest + - ruby rub_tests.rb + - curl --retry 10 --retry-delay 5 -v http://localhost:9200 + diff --git a/run_tests.rb b/run_tests.rb new file mode 100644 index 00000000..6ced2930 --- /dev/null +++ b/run_tests.rb @@ -0,0 +1,44 @@ +require 'selenium-webdriver' +require 'rspec/expectations' +include RSpec::Matchers + +def setup + caps = Selenium::WebDriver::Remote::Capabilities.send("chrome") + @driver = Selenium::WebDriver.for(:remote, url: "http://0.0.0.0:4444/wd/hub", desired_capabilities: caps) + @driver.manage.window.size = Selenium::WebDriver::Dimension.new(1920, 1080) +end + +def teardown + @driver.quit +end + +def run + setup + yield + teardown +end + +run do + container_ip = ARGV[0] + + puts container_ip + + # Open the main page and check for the title + @driver.get "http://#{container_ip}/" + #@driver.save_screenshot(File.join(Dir.pwd, "selenium-docker-main-page.png")) + #@driver.save_screenshot(File.join(Dir.pwd, "selenium-docker-main-page.png")) + expect(@driver.title).to eql 'wp plugindev – Just another WordPress site' + + puts 'title test OK' + + + + + ## Open the chebox page and check if the last checkbox is "checked" + #@driver.get 'http://the-internet.herokuapp.com/checkboxes' + #checkboxes = @driver.find_elements(css: 'input[type="checkbox"]') + #expect(checkboxes.last.selected?).to eql true + + ## Generate a screenshot of the checkbox page + #@driver.save_screenshot(File.join(Dir.pwd, "selenium-docker-checkbox-page.png")) +end diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..d9711cac --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +containerID=$(sudo docker ps | grep plugindevwp | grep -o -e '^\S*') + +containerIP=$( sudo docker inspect --format="{{ .NetworkSettings.IPAddress }}" $containerID) + +ruby run_tests.rb $containerIP