[Selenium+java] How to use IntelliJ idea & Selenium Webdriver

Source: Internet
Author: User
Tags xpath guru99



Original URL: https://www.guru99.com/intellij-selenium-webdriver.html


How to use IntelliJ idea & Selenium Webdriver


Intellij is a IDE that helps your to write better and faster code. Intellij can used in the option to Java Bean and Eclipse.



In this tutorial, you'll learn-


    • What is IntelliJ
    • Pre-requisites to IntelliJ with selenium webdriver
    • How to Download & Install IntelliJ
    • Configure IntelliJ to support Selenium
What is IntelliJ


IntelliJ idea is a Java Integrated development environment (IDE). It's used for software development. It is developed by JetBrains. It comes under Apache2 licenced ' Community Edition ' as well as ' proprietary commercial edition '. It is the finest available Java IDEs. IT provides facilities like advanced code navigation and code refactoring capabilities.



The advantage of using IntelliJ is that


    • It quickly generates getter and setter methods for object attributes.
    • With simple keystrokes, you can wrap a statement in a try-catch or If-else block.
    • The IDE delivers inbuilt packaging tools like Gradle, SBT, Grunt, bower, etc.
    • Database like SQL, ORACLE, PostgreSQL, Microsoft SQL Server can is accessed directly from the IDE.
    • It supports different languages like Java, Javascript, Clojure, etc.
    • It's supported with different operating systems like Windows, Linux, etc. It can downloaded from JetBrains official website.
Pre-requisites to IntelliJ with selenium webdriver


For the, we need to has some pre-requisites which is as follow.


    • IntelliJ
    • Any Web browser (preferably Mozilla Firefox)
    • JDK (Java development Kit)
    • Selenium. jar files


The required jar files can be downloaded from selenium.org official site. After download, the file extracts the. jar files into the desired directory.


How to Download & Install IntelliJ


Step 1) To download IntelliJ visit the JetBrains site. Here we have selected "Community" Version. You can select the "Ultimate" version for mobile, web and enterprise development.






Step 2) When you begin to downloading, you'll see a message like this.






Step 3) In next step, a pop-up window would open. Click on ' Run ' button.






Step 4) In this step, click the "Next" button in the Setup Wizard.






Step 5) Another pop-up window would open. Browse Your destination folder and click on ' Next ' button.






Step 6) In this step,


    1. Mark the Checkbox–32-bit Launcher
    2. Mark the checkbox for language as per your requirement
    3. Click on ' Next ' button





Step 7) In next step, click on ' Install ' button.






You can see IntelliJ installing process are in progress.






Step 8) In this step,


    1. To run IntelliJ, mark the checkbox and
    2. Click the ' Finish ' button





Step 9) If you already has an older version of IntelliJ installed in your system. You can import setting from older version to the newer version. Since we don ' t have any previous version installed. We'll select the second option.






Step Ten) When you click the "OK" button in the previous step, it'll ask for Jetbrain Privacy Policy agreement. Click on ' Accept ' button.






Step One) In this step, you can set plugin setting.






Step) In next step, select the option as per requirement. You'll see the options like create a new project, import project, open, etc.






Step) In this step,


    1. Select the ' Project ' and ' file ' from the library and
    2. Click on ' OK ' button





Step) In this step, the file we selected in the previous step appears in the project directory.





Configure IntelliJ to support Selenium


To the Selenium, you need to configure Inellij. For that follow the following steps.



Step 1) Launch your IntelliJ IDE and make a new Project. Project, Select File , New









Step 2) In the previous step when you Click Next. A New screen would open. In this screen, give project name. In our case, we have given name selenium_guru99. Then Click and Finish. Your Project has been created in IntelliJ.






Step 3) Now you need to add the Selenium's. jar files into IntelliJ as external libraries.



For the Click go to File -and project Structure-A Project setting tab look for Modules -& gt; Dependencies -Click on the ' + ' sign---Select for JARs or directories.






Step 4) Select all the Selenium. jar files from the directory and Subdirectory/lib, where you are extracted after download.






Now, you have successfully added the. jar files into IntelliJ. If you see your project structure and then you'll notice that and project ' S/src directory is empty.



Step 5) Right Click on/src directory , New , Java Class. Your project structure would look as shown below.






Example



We'll use the site http://demo.guru99.com/.



In this test scenario


    • We'll launch the URL
    • Enter Invalid Email ID
    • Click the ' Submit ' button
    • The output would be as shown below-' Email ID was not valid '





In above result, you can see that


    • When we run the code, Firefox instance is open.
    • At the code level, we had provided an e-mail to Webelement. Which is an input field (abc.gmail.com).
    • When Selenium webdriver clicks the ' Submit ' button, the email id was verified by guru99 site.
    • As we said that unregistered email would show message "email ID was not valid."


Following is a Java code for test1.


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestSelenium {											
			public static void main(String[] args){        
				FirefoxDriver driver=new FirefoxDriver();        
				driver.get("http://demo.guru99.com/");        
				WebElement element=driver.findElement(By.xpath("//input[@name=‘emailid‘]"));        
				element.sendKeys("[email protected]");            

				WebElement button=driver.findElement(By.xpath("//input[@name=‘btnLogin‘]"));         
			button.click();    
		}
}


Summary


    • IntelliJ idea is a Java Integrated development environment (IDE).
    • It does has facilities of advanced code navigation and code refactoring capabilities.
    • The advantage of using IntelliJ is
      • Quickly generate getter and setter methods
      • With simple key strokes, you can wrap a statement in a try-catch or If-else block
      • It supports different languages like Java, JavaScript, Clojure, etc.
      • It supports different o.s like Windows, Linux, etc. Inch
    • It comes with inbuilt plugins and packaging tools
    • To use with Selenium, your need to configure IntelliJ


This article was contributed by Fahid M and edited by Jeegar M.






[Selenium+java] How to use IntelliJ idea & Selenium Webdriver


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.