Created
March 11, 2020 04:19
-
-
Save meldsza/4e808125494015e408f97183adf11bd2 to your computer and use it in GitHub Desktop.
ST LAB Part B Program 1 - 11/03/2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.*; | |
import org.openqa.selenium.firefox.*; | |
import org.openqa.selenium.support.ui.*; | |
import org.testng.annotations.*; | |
/** | |
* Open http://172.16.2.90/Part_B1/Mercury_Tours_Demo.html and automate the following using annotations in TestNG framework with Selenium WebDriver. | |
* 1. Verify the title of the homepage | |
* 2. Click on REGISTER and verify the title of its target page | |
* 3. Go back to the homepage and verify if it still has the correct title | |
* 4. Click on SUPPORT and verify if it still has the correct title. | |
* 5. Go back to the homepage and verify if it still has the correct title | |
* 6. Click on CONTACT and verify the title of its target page | |
* 7. Go back to the homepage and verify if it still has the correct title | |
* | |
*/ | |
public class MercuryTest { | |
WebDriver driver; //to store webdriver instance | |
@BeforeTest | |
public void beforeTest() { | |
//set path of gecko driver | |
System.setProperty("webdriver.gecko.driver", "/home/student/geckodriver"); | |
//initialize firefox driver | |
driver = new FirefoxDriver(); | |
//Open the home page | |
driver.get("http://172.16.2.90/Part_B1/Mercury_Tours_Demo.html"); | |
//maximize the window(optional) | |
driver.manage().window().maximize(); | |
} | |
@BeforeMethod | |
public void beforeMethod() { | |
System.out.println("Verifying homepage title"); | |
verifyTitle("Welcome: Mercury Tours"); | |
System.out.println("Homepage title is verified"); | |
} | |
@Test(priority=1) | |
public void verifyRegister() { | |
System.out.println("Verifying register title"); | |
navigateToPage("REGISTER"); | |
verifyTitle("Register: Mercury Tours"); | |
System.out.println("Register title is verified"); | |
System.out.println("Nagivating back to home"); | |
navigateToPage("Home"); | |
} | |
@Test(priority=2) | |
public void verifySupport() { | |
System.out.println("Verifying support title"); | |
navigateToPage("SUPPORT"); | |
verifyTitle("Support: Mercury Tours"); | |
System.out.println("Support title is verified"); | |
System.out.println("Nagivating back to home"); | |
navigateToPage("Home"); | |
} | |
@Test(priority=3) | |
public void verifyContact() { | |
System.out.println("Verifying contact title"); | |
navigateToPage("CONTACT"); | |
verifyTitle("Contact: Mercury Tours"); | |
System.out.println("Contact title is verified"); | |
System.out.println("Nagivating back to home"); | |
navigateToPage("Home"); | |
} | |
@AfterTest | |
public void afterTest() { | |
driver.close(); | |
} | |
/** | |
* Verifies the title of the page | |
*/ | |
private void verifyTitle(String expectedTitle) { | |
assert(expectedTitle.equals(driver.getTitle())); | |
} | |
/** | |
* Navigate to page | |
*/ | |
private void navigateToPage(String pageName) { | |
driver.findElement(By.linkText(pageName)).click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment