WIP docker ruby selenium tests

Former-commit-id: 7b70ce45d5
This commit is contained in:
Leon 2017-03-20 18:21:26 +13:00
parent 83937f6551
commit d59269ecb1
6 changed files with 107 additions and 0 deletions

1
.ruby-version Normal file
View file

@ -0,0 +1 @@
2.4.0

4
Gemfile Normal file
View file

@ -0,0 +1,4 @@
source "https://rubygems.org"
gem 'rspec'
gem 'selenium-webdriver'

36
Gemfile.lock Normal file
View file

@ -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

15
circle.yml Normal file
View file

@ -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

44
run_tests.rb Normal file
View file

@ -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

7
run_tests.sh Executable file
View file

@ -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