Home > other >  Getting this warning after successfully run my selenium program. "WARNING: Connection reset jav
Getting this warning after successfully run my selenium program. "WARNING: Connection reset jav

Time:06-22

package seleniumPractice;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class ToolTip {

public static void main(String[] args) throws InterruptedException {
    
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\m\\Documents\\xyz\\WebDrivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize(); 
    driver.navigate().to("https://www.globalsqa.com/demo-site/tooltip/");

    WebElement globe = driver.findElement(By.xpath("//a[@rel='home']"));
    String expectedTooltip = "GlobalSQA";
    String actualTooltip = globe.getAttribute("title");

    System.out.println("Actual Title of Tool Tip : "   actualTooltip);

    if (actualTooltip.equals(expectedTooltip)) {
        System.out.println("Test Case Passed");
    }
    driver.close();



  }     
}

I have the following versions of google chrome(102.0.5005.115) and chrome driver(102.0.5005.61).

I am using selenium-java version 4.2.1

I am using selenium-chrome-driver version 4.2.1

CodePudding user response:

I would recommend using a try { } finally { } clause, where we don't care as much what happens after you've completed a successful test. I'll take your code and show you what that could look like.

package seleniumPractice;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class ToolTip {

public static void main(String[] args) throws InterruptedException {
    
    try {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\m\\Documents\\xyz\\WebDrivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize(); 
        driver.navigate().to("https://www.globalsqa.com/demo-site/tooltip/");

        WebElement globe = driver.findElement(By.xpath("//a[@rel='home']"));
        String expectedTooltip = "GlobalSQA";
        String actualTooltip = globe.getAttribute("title");

        System.out.println("Actual Title of Tool Tip : "   actualTooltip);

        if (actualTooltip.equals(expectedTooltip)) {
            System.out.println("Test Case Passed");
        }
    }
    finally{
        driver.quit();
    }

  }     
}

CodePudding user response:

Problem got resolved by giving quit(); instead of close();

No need to give try{ } and finally{ }.

One more thing to make sure that you should have same versions of chrome browser and chrome-WebDriver.

  • Related