{"id":38691,"date":"2016-07-30T21:16:25","date_gmt":"2016-07-30T15:46:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=38691"},"modified":"2016-08-01T17:17:29","modified_gmt":"2016-08-01T11:47:29","slug":"automate-selenium-testing-with-jenkins","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/automate-selenium-testing-with-jenkins\/","title":{"rendered":"Automate Selenium testing with Jenkins"},"content":{"rendered":"<p><strong>Selenium<\/strong> is a tool widely used for <a title=\"automation testing services\" href=\"http:\/\/www.tothenew.com\/testing\/automated-independent-manual-testing\">automating testing of web applications<\/a>. One step ahead, integrating the selenium with Jenkins takes it to the next level.<br \/>\nIn this blog, we would be configuring Jenkins to run selenium test cases on an ubuntu environment.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38692\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/js.jpeg\" alt=\"js\" width=\"634\" height=\"94\" \/><\/p>\n<p><strong>Scenario: Configure Jenkins to perform Selenium test cases with one click.<\/strong><\/p>\n<p>I am <a title=\"AWS DevOps\" href=\"http:\/\/www.tothenew.com\/devops-aws\">using Amazon EC2 server<\/a> which has Ubuntu running on it and has Jenkins server installed on it. Since most of the test cases are running on firefox in my case, so I have installed firefox on the server.<\/p>\n<p><strong>Prerequisites<\/strong>:<\/p>\n<ol>\n<li><strong>Install Maven Integration plugin<\/strong>: I am considering this plugin since most of the developers use Maven as a\u00a0build tool for running their test cases.<\/li>\n<li><strong>Install Xvnc plugin<\/strong>: This plugin is required as it creates a web browser instance in memory where all the test cases run.<\/li>\n<li><strong>GIT plugin<\/strong>: I am assuming the code of the test cases is pushed on git, so we would need this plugin to pull the code.<\/li>\n<\/ol>\n<p><span style=\"line-height: 1.71429; font-size: 1rem;\"><strong>Let\u2019s create a Jenkins job for our scenario as below<\/strong>:<\/span><\/p>\n<ol>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Login into your Jenkins server and create a new \u201c<strong>Maven Project<\/strong>\u201d in Jenkins console.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Make the build parameterized if the test cases parameters to be passed to them.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Provide your git repository and branch\/tag in after selecting git under \u201c<strong>Source Code Management<\/strong>\u201d.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Under \u201c<strong>build triggers<\/strong>\u201d, select \u201c<strong>Build whenever a SNAPSHOT dependency is built&#8221;<\/strong> which tells Jenkins to check the snapshot dependencies from the <strong><span style=\"font-weight: 400;\">&lt;dependency&gt; element in the POM, as well as &lt;plugin&gt;s and &lt;extension&gt;s used in POMs.<\/span><\/strong><\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Under \u201c<strong>Build environments<\/strong>\u201d, select \u201c<strong>Run Xvnc during build<\/strong>\u201d. This will provide an X display for the\u00a0<\/span>web<span style=\"line-height: 1.71429; font-size: 1rem;\"> browser to run the <\/span>test cases<span style=\"line-height: 1.71429; font-size: 1rem;\">.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Under \u201c<strong>Build<\/strong>\u201d, provide the path of pom.xml and pass the Goals such as clean, test etc with your profile by using \u201c<strong>-P<\/strong>\u201d if you are using multiple profiles in test cases. If your build is parameterized, the options will be passed with goals and profile with \u201c<strong>-D<\/strong>\u201d.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">In &#8220;<strong>Post Build&#8221; <\/strong>steps, the report generated by Selenium can either be mailed or\u00a0<\/span>served<span style=\"line-height: 1.71429; font-size: 1rem;\">\u00a0from the\u00a0<\/span>server<span style=\"line-height: 1.71429; font-size: 1rem;\"> using <\/span>HTTP<span style=\"line-height: 1.71429; font-size: 1rem;\"> or can be pushed to AWS S3. I found the last option better as AWS S3 is cheap and provide unlimited storage. After uploading the report on AWS S3, the report can be deleted from the server and can be shared using AWS S3 <\/span>URL<span style=\"line-height: 1.71429; font-size: 1rem;\"> so we do not need to serve the report from the server. To upload the\u00a0<\/span>report<span style=\"line-height: 1.71429; font-size: 1rem;\"> to AWS S3 use \u201c <strong>Jenkins S3 publisher plugin<\/strong>\u201d plugin and provide the AWS S3 bucket path where the reports would be uploaded. The report <\/span>URL<span style=\"line-height: 1.71429; font-size: 1rem;\"> from S3 could be shared over mail or can be printed \u00a0in the Jenkins\u2019 logs.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">In case, we need to <\/span>analyze<span style=\"line-height: 1.71429; font-size: 1rem;\"> previous reports, another Jenkins job can be created which can list the desired number of links to the previous reports uploaded on AWS S3.<\/span><\/li>\n<li><span style=\"line-height: 1.71429; font-size: 1rem;\">Now, anyone can run the selenium test cases with a\u00a0<\/span>single<span style=\"line-height: 1.71429; font-size: 1rem;\"> click by accessing the Jenkins\u2019 job.<\/span><\/li>\n<\/ol>\n<p>For more customisation and as per the <a title=\"DevOps Developer\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\">needs of the developer<\/a>, the job can be configured to run on multiple web browsers and it can be passed as a parameter to the Jenkins\u2019 job.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium is a tool widely used for automating testing of web applications. One step ahead, integrating the selenium with Jenkins takes it to the next level. In this blog, we would be configuring Jenkins to run selenium test cases on an ubuntu environment. Scenario: Configure Jenkins to perform Selenium test cases with one click. I [&hellip;]<\/p>\n","protected":false},"author":154,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":8},"categories":[1174,2348,1,1816],"tags":[3853,1853,1332,3855,26,1682,1340,25,3854,2677,3852],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38691"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/154"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=38691"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/38691\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=38691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=38691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=38691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}