{"id":6089,"date":"2020-10-23T19:23:54","date_gmt":"2020-10-23T13:53:54","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=6089"},"modified":"2020-11-16T16:48:57","modified_gmt":"2020-11-16T11:18:57","slug":"5-steps-to-set-up-and-run-a-simple-java-script-in-selenium","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/5-steps-to-set-up-and-run-a-simple-java-script-in-selenium\/","title":{"rendered":"5 Steps to set up and run a simple Java script in Selenium"},"content":{"rendered":"\n<p>Selenium is an automation testing tool. It is widely used because it is an open source and portable for software testing framework for web applications. Selenium supports multiple languages like JAVA, RUBY, PYTHON, C#.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Selenium with Java<\/strong><\/h2>\n\n\n\n<p>The basic Java or core Java language is used to write the selenium script files.&nbsp;<\/p>\n\n\n\n<p>There are steps to set up and run a simple test with java through selenium.<\/p>\n\n\n\n<p>The following components are needed to get started with the <a href=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-webdriver-junit-training-course\">Selenium automation<\/a>:&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Java, which is a programming language to write the test scripts<\/li><li>Eclipse, which is an environment that compiles and runs the java test scripts.<\/li><li>Selenium client and web driver language bindings, is a framework for testing web applications.<\/li><li>Configuring&nbsp; <a href=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-webdriver-junit-training-course\" title=\"Selenium webdriver with Java\">Selenium webdriver with Java<\/a><\/li><li>Creating and running first test.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>Installation of Java<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/RLziI7xgbigbkDCZNkB0dvhvwrGA6sHDIpL9uqFSJIHltUBJVjr0d2UJitNNaXUh4XbvJFNFP7zJv4rfLWelmFxt223EdumZZMrnQu1-Py5zanp7uBKyVAv-cf7g9kP5O9WiB9oHHqyNvPcOog\" alt=\"Download-Java\" title=\"\"><\/figure>\n\n\n\n<p>Java development kit which has JRE (Java Runtime Environment) is required to write and run Java scripts. JRE is a child of JDK. Download Java, install and set up the environment path. After the Java is installed, we need to set up the environment variables to use JDK with Eclipse.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Right click on the My computer .<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/lSepoxL-HhJNUUwMr4HAMXABE8ZFqz_ccoOOvewUT6KLgcgtKKj-nFGazsaNiKs2SNjoJCOS8c7loSVT2uOKYI08vxAG4INp1o2kUgi8jK4e59swEMUVpY0GiPNZObmNrsmHzeHZp-g7eLwnmw\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Go To properties, the system window opens, then click on A<strong>dvanced system<\/strong> settings.<\/li><li>Then system properties window pops up. Click on the <strong>Environment variables<\/strong> under the A<strong>dvanced<\/strong> tab.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/IlI7NQnFwrIWIxySlpBmCOBxkSoi_Lvhxw28R7btTRavVsN2a4DpYG8drqBekz5n-6K8P76CyW3Ju7DVi7WKXLtRtFao038GIcUH0mbjKmDsXRm4VSf_IvZ6nkSyrwi8qZnai5up5Bw8FafN8g\" alt=\"Install-Java-Location\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Click on the environment variables. Click on <strong>New <\/strong>under user variables.<\/li><li>Under the Edit user variables window that pops up, set the variable name as path and variable value as the location of the Bin folder inside the JDK folder on your system. Create a new variable name JAVA_HOME and set the values as the location of the JDK folder.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/yX-i4kXeCee8i00BAbVlRIryCHFVRrgwZ8Y-7mGBupC_wRCm3Z2ScN2FjZobthKAWyrf1u1Uw8BbdKOsRaJJCaoTZTkHjOqgyVLgBayP9oh6myOK0adLdtJqTVUvF__6UMCv1sxCuG__45hI0A\" alt=\"Set-Up-Java-Environment-Path\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/4Z-Jbm4Jih-7lW5GAeupXfpSsJmEjWFE5g_0rI1eEnNBT_Zl8tEGs9dHBAYKDVKcZyFPbpQJ73uWzFZHOMV_8ZNQRg0RwkF7W3TytX8Ejkbonsn14IVLK2OKzAFfF62lv3kvsk4U1E0CtmH_yg\" alt=\"Set-Up-Java-Environment-Path\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. <strong>Installing the Eclipse<\/strong><\/h2>\n\n\n\n<p>Download eclipse by the link <a href=\"http:\/\/www.eclipse.org\/downloads\/\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/www.eclipse.org\/downloads\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/ji7ClxT25-VgGNzZyoUdZImPL8IXu-EF8UwHuKHRSvcHyIfSWU0Zu0eYQy3KCIWMKmImn1_HgqIF2BtBjPT18DByCKRYB66omrD2dt3_keJXmnBxJC5vxBbASMwze7VYsfALi8iVwhdkTw4rPA\" alt=\"Eclipse_Installation_1\" title=\"\"><\/figure>\n\n\n\n<p>Install the Eclipse by clicking the set up file on your system.&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li><strong>Installing the <a href=\"https:\/\/www.h2kinfosys.com\/blog\/category\/selenium-tutorials\/\">Selenium Web Driver<\/a><\/strong><\/li><li>Install the JAR files for selenium by the link&nbsp;<\/li><\/ol>\n\n\n\n<p><a href=\"http:\/\/selenium-release.storage.googleapis.com\/index.html\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/selenium-release.storage.googleapis.com\/index.html<\/a><\/p>\n\n\n\n<p>Select the version and click to install the selenium<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/Qlk3BHGElRvzzHYPBc6pzJfCDscKJSVlck-65Iy9C8q2qjf0GoghxKE8e4fVdzLgW4UUk3LneIHkl1oPkS091Veywh2v9NJbu2Hk--zhve9UwYf6gAn63CEVL7PMfFlJXFIxaclgItf5raH3WA\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/eph-49xZ3ZP-DLHZjyrDvr1QV0Y1mrfYpb_vIhVjFyR4ZV43HQZwVZyyrUak1xVl_jHplhwjb1U__cqxIVqLl1AHTfG1r8QXyVrkZRQ_oPRPDz2rI_90GegeVUEKE9Ez8gqgFLtbSCn-SPAAzg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Download the driver for the internet explorer or any other browser<\/li><li>Then download the third \u2013party plugins, drivers bindings&nbsp;<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/o_o68zjJwau2VXYtvL0nf-szr3h534w9ud3eC3S_L9amt08YSrhSKaENrE13b2iTlXb5Y0i_oZl8a8xIsEE7Duy99r4-VaFV_xIeVhy0bgWDx1C331mUZXP4xdHMxtp4QI7fgprJVraG-NljoA\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\"><li>Downloaded Jar files are stored in your system in the for of zip folders. Extract all files in your system.<\/li><li>Configure the eclipse once all the JAR files of selenium have been added to the system folders.<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li><strong>Create a Java project in Eclipse<\/strong><\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\"><li>Open eclipse window&nbsp;<\/li><li>Right click and click New. A Projectname window is opened.<\/li><li>Provide the projectname as selenium and click on Finish.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/YZyOnSoF2H3X7PWPXhu5qbEIGZYVhiIQSgezMY-XwYzbnUennCB2hkfumtxSO-_xX0eZJR2p9FduQbORxAd5P4xtVBkR3H6oDPnLW-9zeTFUGOZA5ywfU2fJctEI1QTtl6_-028FmYGKPkwcTw\" alt=\"Description: Selenium Java Guide Step 5\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/lKBydpNKRaR0uKSo7zNEduNQApIb2KAPIisog9Y6Ou7qeEunxONIaeSYUaSbSmc5TwF1xH0qJL1o1Q9JnAn8lc2MUB1otk6ryetbFgaRMgokUXq4n837rrHjbivDAEdm8kEhwybQhe-0oy1YOg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Create a&nbsp; package under this project by right clicking \u2018src\u2019 folder<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/r6n84B8Dowe63GUSH8M1UXbm0duMi__bh27MuW83JuL6pqzkKxyzKQb6W1U18INOIwKTewFQgbQ23ayO_oVEgSYsY9Ul2J6j6XDTdcgMkkdDwAg2pr75xjVFs3WAYTj0nLyBhX6GeyQYTQYqKg\" alt=\"Java and Selenium Tutorial Step 6\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>Create the class after the package is created.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/q3mY8PYXtJAzoJm45JwazkenYHpt5hazgVpq_poP-jQLSm7kF4eCuijT3iv10VDpv_tySZs3plA8rgm96cGeQ0WDe4VBk3PaPRLnSf1qF9GdxGhp5gTQBXyc5zwWrfCZSdJZfs-yCwVmzViUUQ\" alt=\"Creating a new class under the package\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\"><li>Once the class is created, add the selenium jars to the project.<\/li><li>To add selenium jars, right click on the project folder and goto properties.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/ZU5UbaYMroc-SCfEoPqMUOIWjRJqMYo_8BOj7cEPu_-XaODAv-nn6JjQj7FGO1BCynNF8Nm6nGeXdQruN6mzKAEV1FLXP44FQu2zHs5b1-tplQh9JVXQ79EaB31MRvKHgRKBZD3kfz-eZtNtfQ\" alt=\"Navigating to Project Build Path in Eclipse\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"8\"><li>From properties window select \u2018Java Build path\u2019 and click on add external JAR\u2019s.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/fucOeRbScQGd-Dyh3W07gTh0ZZYrpRVQvy6RfEIOLDIZOiMtB2CUGNmGnUQk9qUEuNfBmGy1AA4KHdDF8wevAaW4jnCK_UMOljSA8l-6Whj-sc9Wc2EwJ_UHb5SsK3exTsw11NxKGkCBS9zDDg\" alt=\"Java Build Path Configuration to include Selenium WebDriver Jars\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"9\"><li>Add the downloaded selenium jars and click on apply. Write the test script and prepare to execute the test script.<\/li><\/ol>\n\n\n\n<p>5.<strong> Write an open program to open browser<\/strong><\/p>\n\n\n\n<p>a. After creating Package and class, write the program for example to open the Firefox browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/ksXYH9jsoEm1v6p8-WrNpuxf6Pm_emklrcDnSAehMdpqkovJXZzYdL8h3377-MrR7xv0uJuUO0saizYA5S6OE9E8LaauJpHfgcioFcSQ_HOtwsTDmuk7msOePc1o52eM7vMzsD6bs2d5jeePZw\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>b. after completion Run and validate the test script.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/6YYz2hkfiry3ZxiUlkxe_GtoaDZ30QAtWDbUiwmGrvdonEN_SKEtFO1E1v19WZFazzSLf-ZkSrn8PgXJ61Z7ihM7nrOORKLY6OLCzlFlrHJ_KvoLDqAIdoVsh48-QqnOM2qLghb-AaeXoMLudw\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>Keep a separate folder within the project to keep all jars. This is useful in better organisation. Selenium webdriver is not having built in report facility. Use the programming control flow statements or testing framework verification method which generates test results. Selenium overcomes the drawbacks of Selenium Remote Control which offers better support for dynamic pages where the elements on a page are changing without the support of page itself reloaded.Selenium uses each browser\u2019s native support for automation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium is an automation testing tool. It is widely used because it is an open source and portable for software testing framework for web applications. Selenium supports multiple languages like JAVA, RUBY, PYTHON, C#. Selenium with Java The basic Java or core Java language is used to write the selenium script files.&nbsp; There are steps [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6840,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6089","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=6089"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6089\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/6840"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=6089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=6089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=6089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}