After loading the ide, open the folder structure and locate and move to selenium/src/main/java/com/hackerearth/fullstack/backend/AutomationScripts.java file and write the solution for the mentioned tasks.
Here is the solution to question [Java] Marvel cinematic universe
package com.hackerearth.fullstack.backend;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.springframework.stereotype.Component;
@Component
public class AutomationScripts {
public AutomationScripts() {
System.setProperty("webdriver.chrome.driver", "chromedriver1eebc8c");
}
public Result Marvel(WebDriver driver) throws InterruptedException {
String website_title = "";
List<String> phase1_movies = new ArrayList<>();
List<String> phase2_movies = new ArrayList<>();
List<String> phase3_movies = new ArrayList<>();
// Task 1 - Open "https://www.google.com/" and search "List of Marvel Cinematic Universe films" and click on first link,
// store the title of resulting website in website_title
driver.get("https://www.google.com/");
driver.findElement(By.name("q")).sendKeys("List of Marvel Cinematic Universe films");
driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
driver.findElement(By.className("yuRUbf")).click();
website_title = driver.getTitle();
System.out.println(website_title);
// Task 2 - Retrieve the first 5 phase 1 movies of marvel in phase1_movies list.
for(int i=2; i<8; i++) {
String x = driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/main/div[3]/div[3]/div[1]/table[2]/tbody/tr["+i+"]/th/i/a")).getText();
phase1_movies.add(x);
}
System.out.println((phase1_movies));
// Task 3 - Retrieve the first 5 phase 2 movies of marvel in phase2_movies list.
for(int i=2; i<8; i++) {
String x = driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/main/div[3]/div[3]/div[1]/table[3]/tbody/tr["+i+"]/th/i/a")).getText();
phase2_movies.add(x);
}
System.out.println((phase2_movies));
// Task 4 - Retrieve the first 5 phase 3 movies of marvel in phase3_movies list.
for(int i=2; i<13; i++) {
String x = driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/main/div[3]/div[3]/div[1]/table[4]/tbody/tr["+i+"]/th/i/a")).getText();
phase3_movies.add(x);
}
System.out.println((phase3_movies));
return new Result(website_title, phase1_movies, phase2_movies, phase3_movies);
}
}
When the candidates have completed their code, they can click the "Run Code" button to test it against sample test cases. These sample test cases do not affect the candidate's score. After that, If the sample test cases pass, the candidate can click Submit Code to evaluate it against the main test cases for the actual test score. If the sample or main test cases do not pass, the candidate can review the execution and build logs for compilation errors, and revise their code accordingly.