Checked website responsive code
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ImageBlurCheck {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("browserVersion", "117");
WebDriver driver = new ChromeDriver(chromeOptions);
try {
//Add your testing website URL here
driver.get("https://www.example.com");
testTitle(driver);
testHeader(driver);
testFooter(driver);
checkContent(driver);
testResponsive(driver);
} catch (Exception e) {
System.err.println("An error occurred while testing: " + e.getMessage());
} finally {
driver.quit();
}
}
private static void testTitle(WebDriver driver) {
String expectedTitle = "Your Trusted Web Design and Development Agency | cmsMinds";
String actualTitle = driver.getTitle();
System.out.println(actualTitle.equals(expectedTitle) ? "Title Test Passed!" :
"Title Test Failed! Expected: " + expectedTitle + ", Actual: " + actualTitle);
}
private static void testHeader(WebDriver driver) {
WebElement headerElement = driver.findElement(By.tagName("h1"));
String headerText = headerElement.getText();
System.out.println(!headerText.isEmpty() ? "Header Test Passed! Header Text: " + headerText :
"Header Test Failed! Header Text is empty.");
}
private static void testFooter(WebDriver driver) {
WebElement footerElement = driver.findElement(By.tagName("footer"));
System.out.println(footerElement.isDisplayed() ? "Footer Test Passed!" :
"Footer Test Failed! Footer is not displayed.");
}
private static void checkContent(WebDriver driver) {
String expectedText = "We Build and Support Websites that";
String bodyText = driver.findElement(By.tagName("body")).getText();
System.out.println(bodyText.contains(expectedText) ? "Text '" + expectedText + "' is present on the page." :
"Text '" + expectedText + "' is not present on the page.");
}
private static void testResponsive(WebDriver driver) {
int[][] deviceSizes = {{1920, 1080}, {768, 1024}, {375, 667}};
for (int[] size : deviceSizes) {
driver.manage().window().setSize(new Dimension(size[0], size[1]));
WebElement mobileMenuIcon = driver.findElement(By.cssSelector(".humburger-bar-icon"));
System.out.println(mobileMenuIcon.isDisplayed() && mobileMenuIcon.isEnabled() ?
"Mobile Menu Icon is properly visible and clickable at size " + size[0] + "x" + size[1] + "." :
"Mobile Menu Icon is not properly visible or clickable at size " + size[0] + "x" + size[1] + ".");
}
}
}
0 Comments