Automation QA Testing Course Content

Validating top 35 inspirational movies in IMDB website using Selenium WebDriver

package linkprograms;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Top35InspirationalMovieTest {

public static void main(String[] args) throws InterruptedException {
//set the chromedriver.exe path
System.setProperty("webdriver.chrome.driver", "D:\\webdriverjars\\executables\\chromedriver_win32\\chromedriver.exe");
//interface refobj=new implementingclass();
WebDriver driver=new ChromeDriver();
//open the google.com
driver.navigate().to("https://www.imdb.com/list/ls000632473/");
//maximize the window
driver.manage().window().maximize();
//add implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//create object for WebDriverWait class
WebDriverWait wait=new WebDriverWait(driver,30);

//fetch all the movie links from top inspirational movies section using findElemnts API
List<WebElement>top35inspLinksList=driver.findElements(By.xpath("//div[@class='lister-item-content']"));

for(int i=1;i<=top35inspLinksList.size();i++) {
System.out.println("************************************************");
//fetch the movie link name
String movielinkName=driver.findElement(By.xpath("//*[@id='main']/div/div[3]/div[3]/div["+i+"]/div[2]/h3/a")).getText();
System.out.println("link name is -->"+movielinkName);
//fetch the url of the each link
String movielinkurl=driver.findElement(By.xpath("//*[@id='main']/div/div[3]/div[3]/div["+i+"]/div[2]/h3/a")).getAttribute("href");
System.out.println(movielinkName+" url is-->"+movielinkurl);
//click on each link
driver.findElement(By.xpath("//*[@id='main']/div/div[3]/div[3]/div["+i+"]/div[2]/h3/a")).click();
if(driver.getTitle().contains(movielinkName)) {
System.out.println("correct movie page is displayed for the link:"+driver.getTitle());
}else {
System.out.println("correct page is not displayed"+driver.getTitle());
}
//naviagte to previous page
driver.navigate().back();

}
Thread.sleep(3000);
//close the browser
driver.close();
}

}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.