{"id":2281,"date":"2010-10-01T11:45:45","date_gmt":"2010-10-01T09:45:45","guid":{"rendered":"https:\/\/test.viaboxx.de\/2010\/10\/01\/start-your-webtests-with-selenium2-maven-testng-now\/"},"modified":"2021-08-20T10:21:06","modified_gmt":"2021-08-20T10:21:06","slug":"start-your-webtests-with-selenium2-maven-testng-now","status":"publish","type":"post","link":"https:\/\/www.viaboxx.de\/en\/blog\/start-your-webtests-with-selenium2-maven-testng-now\/","title":{"rendered":"Start your webtests with Selenium2, Maven, TestNG \u2013 now"},"content":{"rendered":"\n<p>Every time you are playing around with web tests you think: why have I waited so long. Doesn\u2019t matter, you have done it and that\u2019s it what matters.<\/p>\n\n\n\n<p>The last time I used Selenium 1 which is very often used for web tests. Selenium 1 is great, but has a few limitations. It is based around an injected Javascript library \u2013 the Selenium core. It works, but starting the browser with the Selenium core is often a little bit tricky. With every browser update you hope that it is still running or hope for the update, which needs to be included in the Maven plugin, is pushed to the Maven mirrors, is really working on all systems, \u2026<\/p>\n\n\n\n<p>But now there is Selenium 2 with the merge of Webdriver. It is no longer a Javascript core, it is a native browser plugin. And now you are much deeper inside the browser. It feels more stable from the first second and it works really well. With the Webdriver part of Selenium 2 there is a new API. But it isn\u2019t very complicated, just different.<\/p>\n\n\n\n<p>I can give you a damn short example which works really well for me and runs through our entire webpage. The great part: it takes screenshots of the complete page (not just the visible part) and stores them in the target folder.<\/p>\n\n\n\n<p>First of all, the Maven pom:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[codesyntax lang=\"xml\"]\n&lt;pre&gt;&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt;\n&amp;lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n         xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n         xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&amp;gt;\n    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;\/modelVersion&amp;gt;\n \n    &amp;lt;groupId&amp;gt;de.viaboxx.tests&amp;lt;\/groupId&amp;gt;\n    &amp;lt;artifactId&amp;gt;integrationtest&amp;lt;\/artifactId&amp;gt;\n    &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;\/version&amp;gt;\n \n    &amp;lt;dependencies&amp;gt;\n        &amp;lt;dependency&amp;gt;\n            &amp;lt;groupId&amp;gt;org.testng&amp;lt;\/groupId&amp;gt;\n            &amp;lt;artifactId&amp;gt;testng&amp;lt;\/artifactId&amp;gt;\n            &amp;lt;version&amp;gt;5.13.1&amp;lt;\/version&amp;gt;\n            &amp;lt;scope&amp;gt;test&amp;lt;\/scope&amp;gt;\n        &amp;lt;\/dependency&amp;gt;\n \n        &amp;lt;dependency&amp;gt;\n            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;\/groupId&amp;gt;\n            &amp;lt;artifactId&amp;gt;selenium&amp;lt;\/artifactId&amp;gt;\n            &amp;lt;version&amp;gt;2.0a6&amp;lt;\/version&amp;gt;\n        &amp;lt;\/dependency&amp;gt;\n \n        &amp;lt;dependency&amp;gt;\n            &amp;lt;groupId&amp;gt;org.seleniumhq.selenium&amp;lt;\/groupId&amp;gt;\n            &amp;lt;artifactId&amp;gt;selenium-firefox-driver&amp;lt;\/artifactId&amp;gt;\n            &amp;lt;version&amp;gt;2.0a6&amp;lt;\/version&amp;gt;\n        &amp;lt;\/dependency&amp;gt;\n    &amp;lt;\/dependencies&amp;gt;\n \n    &amp;lt;build&amp;gt;\n        &amp;lt;plugins&amp;gt;\n            &amp;lt;plugin&amp;gt;\n                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;\/groupId&amp;gt;\n                &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;\/artifactId&amp;gt;\n                &amp;lt;configuration&amp;gt;\n                    &amp;lt;skip&amp;gt;true&amp;lt;\/skip&amp;gt;\n                &amp;lt;\/configuration&amp;gt;\n                &amp;lt;executions&amp;gt;\n                    &amp;lt;execution&amp;gt;\n                        &amp;lt;phase&amp;gt;integration-test&amp;lt;\/phase&amp;gt;\n                        &amp;lt;goals&amp;gt;\n                            &amp;lt;goal&amp;gt;test&amp;lt;\/goal&amp;gt;\n                        &amp;lt;\/goals&amp;gt;\n                        &amp;lt;configuration&amp;gt;\n                            &amp;lt;skip&amp;gt;false&amp;lt;\/skip&amp;gt;\n                        &amp;lt;\/configuration&amp;gt;\n                    &amp;lt;\/execution&amp;gt;\n                &amp;lt;\/executions&amp;gt;\n            &amp;lt;\/plugin&amp;gt;\n            &amp;lt;plugin&amp;gt;\n                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;\/groupId&amp;gt;\n                &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;\/artifactId&amp;gt;\n                &amp;lt;configuration&amp;gt;\n                    &amp;lt;source&amp;gt;1.5&amp;lt;\/source&amp;gt;\n                    &amp;lt;target&amp;gt;1.5&amp;lt;\/target&amp;gt;\n                &amp;lt;\/configuration&amp;gt;\n            &amp;lt;\/plugin&amp;gt;\n        &amp;lt;\/plugins&amp;gt;\n    &amp;lt;\/build&amp;gt;\n&amp;lt;\/project&amp;gt;&lt;\/pre&gt;\n[\/codesyntax]<\/pre>\n\n\n\n<p>And it follows the hole logic for the test placed under src\/test\/java\/de\/viaboxx\/tests\/SeleniumTest.java:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[codesyntax lang=\"java\"]\n&lt;pre&gt;package de.viaboxx.tests;\n \nimport org.apache.commons.io.FileUtils;\nimport org.openqa.selenium.OutputType;\nimport org.openqa.selenium.firefox.FirefoxDriver;\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\n \nimport java.io.File;\nimport java.io.IOException;\n \npublic class SeleniumTest {\n    private static final String FOLDER_NAME = \"target\/screenshots\/\";\n \n    @Test\n    public void website() throws IOException, InterruptedException {\n        FirefoxDriver driver = new FirefoxDriver();\n        driver.get(\"http:\/\/www.viaboxxsystems.de\");\n        Assert.assertEquals(driver.findElementByXPath(\"\/\/h2\").getText(), \"Innovation\");\n        FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE), new File(FOLDER_NAME + \"startpage.png\"));\n \n        driver.findElementByLinkText(\"Team\").click();\n        Assert.assertEquals(driver.findElementByXPath(\"\/\/h2\").getText(), \"Team\");\n        FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE), new File(FOLDER_NAME + \"team.png\"));\n \n        driver.findElementByLinkText(\"Blog\").click();\n        FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE), new File(FOLDER_NAME + \"blog.png\"));\n \n        driver.findElementByLinkText(\"Impressum\").click();\n        FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE), new File(FOLDER_NAME + \"impressum.png\"));\n \n        driver.close();\n    }\n \n}&lt;\/pre&gt;\n[\/codesyntax]<\/pre>\n\n\n\n<p>Run it with:<\/p>\n\n\n\n<pre class=\"wp-block-code notranslate\"><code>mvn integration-test<\/code><\/pre>\n\n\n\n<p>Readable, isn\u2019t it. And that\u2019s all \u2013 a complete working infrastructure for your web tests. The example works with Firefox, but you can also run headless with HtmlUnit, or make your tests running in IE or Chrome. The great thing: just put the application in your continuous integration server and run it on your defined build agent.<\/p>\n\n\n\n<p>After just one evening I fall in love with the new Selenium 2. Why? Because it works much more stable in kind of browser starting and running. I think it is a great way to go.<\/p>\n\n\n\n<p>Watch the screenshots, just taken from the target folder:<\/p>\n\n\n\n<section class=\"wp-block-uagb-columns uagb-columns__wrap uagb-columns__background-undefined uagb-columns__stack-mobile uagb-columns__valign-undefined uagb-columns__gap-10 alignundefined uagb-block-55cd6630\"><div class=\"uagb-columns__overlay\"><\/div><div class=\"uagb-columns__inner-wrap uagb-columns__columns-2\">\n<div class=\"wp-block-uagb-column uagb-column__wrap uagb-column__background-undefined uagb-block-5861956c\"><div class=\"uagb-column__overlay\"><\/div><div class=\"uagb-column__inner-wrap\">\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"294\" height=\"300\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2010\/10\/startpage-294x300.png\" alt=\"\" class=\"wp-image-7082\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2010\/10\/startpage-294x300.png 294w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2010\/10\/startpage-768x785.png 768w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2010\/10\/startpage.png 1000w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/figure><\/div>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-uagb-column uagb-column__wrap uagb-column__background-undefined uagb-block-93ad06a3\"><div class=\"uagb-column__overlay\"><\/div><div class=\"uagb-column__inner-wrap\">\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img loading=\"lazy\" decoding=\"async\" width=\"294\" height=\"300\" src=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2021\/08\/team-294x300.png\" alt=\"\" class=\"wp-image-7084\" srcset=\"https:\/\/www.viaboxx.de\/wp-content\/uploads\/2021\/08\/team-294x300.png 294w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2021\/08\/team-768x785.png 768w, https:\/\/www.viaboxx.de\/wp-content\/uploads\/2021\/08\/team.png 1000w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/figure><\/div>\n<\/div><\/div>\n<\/div><\/section>\n\n\n\n<p class=\"has-normal-font-size\"><strong>More documentation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/seleniumhq.org\/\">http:\/\/seleniumhq.org\/<\/a><\/li><li><a href=\"http:\/\/seleniumhq.org\/docs\/09_webdriver.html\">http:\/\/seleniumhq.org\/docs\/09_webdriver.html<\/a><\/li><li><a href=\"http:\/\/maxheapsize.com\/2010\/01\/04\/using-selenium-2-for-web-testing\/\">http:\/\/maxheapsize.com\/2010\/01\/04\/using-selenium-2-for-web-testing\/<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Every time you are playing around with web tests you think: why have I waited so long. Doesn\u2019t matter, you have done it and that\u2019s it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[76],"tags":[],"class_list":["post-2281","post","type-post","status-publish","format-standard","hentry","category-code"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Simon Tiffert","author_link":"https:\/\/www.viaboxx.de\/en\/blog\/author\/simon-tiffertviaboxx-de\/"},"uagb_comment_info":0,"uagb_excerpt":"Every time you are playing around with web tests you think: why have I waited so long. Doesn\u2019t matter, you have done it and that\u2019s it [&hellip;]","_links":{"self":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2281"}],"collection":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/comments?post=2281"}],"version-history":[{"count":6,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2281\/revisions"}],"predecessor-version":[{"id":7138,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/posts\/2281\/revisions\/7138"}],"wp:attachment":[{"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/media?parent=2281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/categories?post=2281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.viaboxx.de\/en\/wp-json\/wp\/v2\/tags?post=2281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}