From cb8795755a42a31d600ed7403b3c1bdbcf88ea54 Mon Sep 17 00:00:00 2001 From: Benjamin Stein Date: Fri, 12 May 2017 14:14:08 -0700 Subject: [PATCH] Add selenium (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- Jenkinsfile | 65 ++++++++++++++++++++++++++++++++--------------- petclinic_spec.rb | 37 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 petclinic_spec.rb diff --git a/Jenkinsfile b/Jenkinsfile index 02d247874..4ca9d87d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,27 +1,50 @@ pipeline { - agent { - docker { - image 'maven:3.5.0' - args '--network=plumbing_default' - } - } + agent none stages { - stage ('Build') { - steps { - configFileProvider( - [configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) { - sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true' - } - } - } - stage ('Deploy to Tomcat') { - steps { - sh 'cp target/petclinic.war /usr/share/jenkins/ref/petclinic/petclinic.war' - } - } - stage ('Sonar') { + stage('Build') { + agent { + docker { + image 'maven:3.5.0' + args '--network=plumbing_default' + } + } steps { - sh '/var/jenkins_home/sonar/bin/sonar-runner' + configFileProvider( + [configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true' + } + } + } + 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 '/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' } } } diff --git a/petclinic_spec.rb b/petclinic_spec.rb new file mode 100644 index 000000000..44d625a6b --- /dev/null +++ b/petclinic_spec.rb @@ -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