zoukankan      html  css  js  c++  java
  • [Selenium+Java] How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Intellij is an IDE that helps you to write better and faster code. Intellij can be used in the option to Java bean and Eclipse.

    In this tutorial, you will learn-

    What is intelliJ

    IntelliJ IDEA is a Java Integrated Development Environment (IDE). It is 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 be accessed directly from the IDE.
    • It supports different languages like Java, Javascript, Clojure, etc.
    • It is supported with different operating systems like Windows, Linux, etc. It can be downloaded from JetBrains official website.

    Pre-requisites to IntelliJ with selenium webdriver

    For that, we need to have some pre-requisites which are 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 "ultimate" version for mobile, web and enterprise development.

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 2) When you begin downloading, you will see a message like this.

    How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 4) In this step, click on 'next' button in the setup wizard.

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 5) Another pop-up window will open. Browse your destination folder and click on 'next' button.

    How to use IntelliJ IDEA & Selenium Webdriver

    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

    How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

    You can see IntelliJ installing process is in progress.

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 8) In this step,

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 9) If you already have 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 will select the second option.

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 10) When you click on 'ok' button in the previous step, it will ask for Jetbrain privacy policy agreement. Click on 'Accept' button.

    How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 13) In this step,

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

    How to use IntelliJ IDEA & Selenium Webdriver

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Configure IntelliJ to Support Selenium

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

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

    How to use IntelliJ IDEA & Selenium Webdriver

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 2) In the previous step when you Click -> Next. A new screen will open. In this screen, give project name. In our case, we have given name Selenium_Guru99. Then Click -> Finish. Your project has been created in IntelliJ.

    How to use IntelliJ IDEA & Selenium Webdriver

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

    For this Click go to File -> Project Structure -> in a project setting tab look for Modules ->Dependencies -> Click on '+' Sign -> Select for JARs or directories.

    How to use IntelliJ IDEA & Selenium Webdriver

    Step 4) Select all the selenium .jar files from the directory and subdirectory /lib, where you have extracted after download.

    How to use IntelliJ IDEA & Selenium Webdriver

    Now, you have successfully added the .jar files into intelliJ. If you see your project structure, then you will notice that you project's /src directory is empty.

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

    How to use IntelliJ IDEA & Selenium Webdriver

    Example

    We will use the site http://demo.guru99.com/.

    In this test scenario

    • We will launch the URL
    • Enter Invalid Email ID
    • Click the 'Submit' button
    • The output will be as shown below- 'Email id is not valid'

    How to use IntelliJ IDEA & Selenium Webdriver

    In above result, you can see that

    • When we run the code, Firefox instance is open.
    • At code level, we have provided an email to webelement. Which is an input field (abc.gmail.com).
    • When Selenium Webdriver clicks the 'submit' button, email id is verified by guru99 site.
    • As we said that unregistered email would show message "Email ID is not valid."

    Following is 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("abc@gmail.com");            
    
    				WebElement button=driver.findElement(By.xpath("//input[@name='btnLogin']"));         
    			button.click();    
    		}
    }
    

    Summary

    • IntelliJ IDEA is a Java Integrated Development Environment (IDE).
    • It does have 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.In
    • It comes with inbuilt plugins and packaging tools
    • To use with Selenium, you need to configure IntelliJ

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

  • 相关阅读:
    Centos6.5环境中安装vsftp服务
    MySQL数据库的数据备份和恢复(导入和导出)命令操作语法【转】
    linux系统被入侵后处理经历【转】
    Linux lsof命令详解和使用示例【转】
    Oracle 表空间和用户权限管理【转】
    如何在 Linux 中找出最近或今天被修改的文件
    Linux 服务器系统监控脚本 Shell【转】
    1张图看懂RAID功能,6张图教会配置服务器【转】
    简析TCP的三次握手与四次分手【转】
    TCP协议中的三次握手和四次挥手(图解)【转】
  • 原文地址:https://www.cnblogs.com/alicegu2009/p/9098731.html
Copyright © 2011-2022 走看看