Add selenium (#7)

* Fixed formatting

* Put cp back

* Move agent to stage level

* Added agents per stage

* Added pipeline level agent declaration

* Formatted agents

* removed :

* need steps in every stage

* requires files on jenkins, using sonar without a container. 7/10 chance of working

* using sonar container. 4/10 chance of working

* specify network for sonar container

* Use Ruby image

* test container

* Added selenium.rb with hello world

* first headless test

* fix quotes

* fix quotes

* added Headless dependecy

* Fix dependency

* Install Firefox driver

* Attempt to fix missing firefox package

* zzzz

* corrected firefox

* Added geckkodriver

* add firefox

* Removed extra quotes

* Display page title

* Comments and simplifying

* Point to Petclinic

* uncomment all the build stages

* comment out steps

* comment out steps

* use correct port for tomcat

* adding first test

* adding dockerfile for selenium testing

* Added minitest setup

* Fix if

* Fixed test invokation

* Don’t use Petclinic class

* Use instance variables

* fix expectation

* adding volume mounting

* Added minitest

* using new selenium docker image in test portion of pipeline

* using assert for first test

* removing dockerfile

* one working test
This commit is contained in:
Benjamin Stein 2017-05-12 14:14:08 -07:00 committed by GitHub
parent e5ef12d536
commit cb8795755a
2 changed files with 81 additions and 21 deletions

29
Jenkinsfile vendored
View file

@ -1,12 +1,13 @@
pipeline {
agent none
stages {
stage('Build') {
agent {
docker {
image 'maven:3.5.0'
args '--network=plumbing_default'
}
}
stages {
stage ('Build') {
steps {
configFileProvider(
[configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) {
@ -15,13 +16,35 @@ pipeline {
}
}
stage('Deploy to Tomcat') {
agent {
docker {
image 'alpine'
}
}
steps {
sh 'cp target/petclinic.war /usr/share/jenkins/ref/petclinic/petclinic.war'
}
}
stage('Sonar') {
agent {
docker {
image 'sebp/sonar-runner'
args '--network=plumbing_default'
}
}
steps {
sh '/var/jenkins_home/sonar/bin/sonar-runner'
sh '/opt/sonar-runner-2.4/bin/sonar-runner'
}
}
stage('Selenium') {
agent {
docker {
image 'stein321/selenium-firefox'
args '--network=plumbing_default'
}
}
steps {
sh 'ruby petclinic_spec.rb'
}
}
}

37
petclinic_spec.rb Normal file
View file

@ -0,0 +1,37 @@
require 'headless'
require 'selenium-webdriver'
require 'minitest/spec'
require 'minitest/autorun'
describe 'Petlinic' do
before do
@headless = Headless.new
@headless.start
@driver = Selenium::WebDriver.for :firefox
@driver.navigate.to 'http://dashboard:8080/petclinic'
@wait = Selenium::WebDriver::Wait.new(:timeout => 3)
end
after do
@headless.destroy
end
describe 'when homepage is available' do
it 'I should see Page title' do
puts "Title is: #{@driver.title}"
assert @driver.title == "PetClinic :: a Spring Framework demonstration"
end
end
# describe 'when homepage is available' do
# it 'click the find owners button' do
# @driver.find_element(:class, "icon-search").click
# form = @driver.find_element(:id, "lastName")
# puts "form is #{form.label}"
# assert @driver.title == "PetClinic :: a Spring Framework demonstration"
# end
# end
end