Maven Project Freamework Programming Worksheet
ANSWER
To automate the steps you mentioned using a Maven project with the TestNG framework, you’ll need to use Selenium WebDriver, a popular tool for automating web applications. Here’s a basic outline of how you can create a script to perform these actions:
Note: Before proceeding, ensure that you have set up a Maven project and added the necessary dependencies for Selenium WebDriver and TestNG in your project’s pom.xml
file.
- Create a Java class, e.g.,
ExpediaFlightAutomation
, and set up your WebDriver instance.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ExpediaFlightAutomation {
WebDriver driver;
public void setUp() {
// Set the WebDriver executable path (Download and specify your browser's driver)
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver = new ChromeDriver();
}
public void bookFlight() {
// Navigate to Expedia website
driver.get("https://www.expedia.com");
// Perform the steps you mentioned
// i. Click on flights tab
// ii. Fill the form to search for roundtrip flight and click on search button
// iii. Select round trip flights
// iv. Switch to other tab
// v. Click on checkout
// vi. Fill passenger's information
// Add your code here
// Example: Click on the flights tab (You need to locate elements using WebDriver)
// driver.findElement(By.id("flights-tab")).click();
// Add code for other steps here
}
public void tearDown() {
// Close the WebDriver instance after the test
driver.quit();
}
}
- In the
bookFlight
method, you’ll need to use WebDriver commands to locate and interact with elements on the Expedia website as described in your steps. You should inspect the website’s HTML to identify the elements you need to interact with (e.g., buttons, input fields) and use WebDriver’s methods likefindElement
andclick
to interact with them. - Implement the remaining steps (iii to vi) by finding the relevant elements and performing actions like clicking buttons, filling forms, and switching tabs.
- Make sure to handle any necessary waits (e.g.,
WebDriverWait
) and error handling in your script. - You can run this TestNG test class to automate the specified steps on the Expedia website.
Remember to replace "path/to/chromedriver"
with the actual path to your Chrome WebDriver executable and adjust the code as needed to interact with the Expedia website elements correctly. Additionally, you may need to install the Chrome WebDriver and ensure your browser is compatible with the WebDriver version you are using.
QUESTION
Description
I need only basics
Go to https://expedia.com and create a script by using Maven project with TestNG framework for following steps:
i. Click on flights tab
ii. Fill the form to search flight for roundtrip and click on search button
iii. Select round trip flights
v. Switch to other tab v. Click on checkout
vi. Fill the passenger’s information
![Place Your Order Here](http://scholarywriters.com/wp-content/uploads/2023/08/Bottom-of-every-post.png)