Перейти к содержимому

Как найти неработающие ссылки в веб-приложении с помощью Selenium | Прадип Найлвал

Lets Make Automation Easy - Pradeep Nailwal

0:00 / 0:00

Как найти неработающие ссылки в веб-приложении с помощью Selenium | Прадип Найлвал

5 240 просмотров · 3 года назад
Lets Make Automation Easy - Pradeep Nailwal
9,13 тыс. подписчиков
5 240 просмотров · 3 года назад
package com.org.selenium; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class BrokenHyperlinks { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "E:\\Drivers\\Chrome109\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://localhost:8080/AdhisaClassesWebApplication/"); HttpURLConnection huc = null; List allHyperlinksList = driver.findElements(By.tagName("a")); for (Object hyperLink : allHyperlinksList) { String url = ((WebElement)hyperLink).getAttribute("href"); try { URL actualUrl = new URL(url); huc = (HttpURLConnection) actualUrl.openConnection(); huc.setRequestMethod("HEAD"); huc.connect(); int respCode = huc.getResponseCode(); if (respCode == 400) { System.out.println(url + " is a BROKEN link"); } else { System.out.println(url + " is a VALID link"); } } catch (Exception e) { e.printStackTrace(); } } } -------------------------------------------------------------------------------------------------------------------------------- #java #restassured #soapui #postman #extentreport #selenium #jmeter #api #testing #training #refermegroup #jenkins #maven #github #apitesting #cicd #agiletesting #cucumber #sonar #robotframework #Error #Defect #Bug #Failure #api #webdesigner #webdriver #web #java #html #html5 #performance #manualtesting #junit #mutable #immutable #singleton #casting #synchronization #jmeter Посетите мой канал, чтобы узнать больше о концепциях ручного тестирования, таких как #Error, #Defect, #Bug и #Failure