Selenium Assignment – 1

Here is the first assignment of this series of real-time scenarios, to practice Selenium from QA Tech hub. This assignment mainly focuses on how to invoke the Firefox browser, maximizing the window, navigate commands, etc.

This assignment is not considering proper framework development. Once you are good with frameworks, try this again considering framework.

Note: If you are very new to selenium, go through Environment setup for Selenium WebDriver and other articles before starting.

Scenario:

  1. Open the Firefox browser.
  2. Maximize the browser window.
  3. Navigate to “http://qatechhub.com”.
  4. Write a method to print PASS if the title of the page matches with “QA Automation Tools Trainings and Tutorials | QA Tech Hub” else FAIL. (If you are familiar with TestNG or JUnit use assert statement like assert.assertequals(actual, expected) to give a verdict of the pass or fail status.
  5. Navigate to the Facebook page (https://www.facebook.com)
  6. Navigate back to the QA Tech Hub website.
  7. Print the URL of the current page.
  8. Navigate forward.
  9. Reload the page.
  10. Close the Browser.

Try this code. Send us the code for feedback and assessment, or if you have any questions, queries or comments. Feel free to write us support@qatechhub.com. Keep Learning 🙂

Here is the link to the Second Assignment.

Below code you can refer if you are a beginner:

package assignments;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Assignment1 {

	// Creating an instance of Firefox Browser
	FirefoxDriver driver;
	String qatechhubUrl = "http://qatechhub.com";
	String facebookUrl = "https://www.facebook.com";

	public void invokeBrowser() {

		System.setProperty("webdriver.gecko.driver",
				"C:\\Users\\Saurabh Dhingra\\workspace\\libs\\geckodriver-v0.20.1-win64\\geckodriver.exe");
		driver = new FirefoxDriver();

		driver.manage().window().maximize();

		driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

		driver.get(qatechhubUrl);

		String titleOfThePage = driver.getTitle();

		if (titleOfThePage.equals("QA Automation Tools Trainings and Tutorials | QA Tech Hub")) {
			System.out.println("Test case PASS");
		} else {
			System.out.println("Test case FAIL");
		}

	}

	public void navigateCommands() {
		driver.navigate().to(facebookUrl);

		String currentUrl = driver.getCurrentUrl();

		System.out.println("Current URL :: " + currentUrl);
		driver.navigate().back();

		driver.navigate().refresh();

		driver.navigate().refresh();
	}

	public static void main(String[] args) {
		Assignment1 assignment = new Assignment1();

		assignment.invokeBrowser();

	}

}

In case you are familiar with TestNG or JUnit use below code:

package assignments;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class Assignment1 {

	// Creating an instance of Firefox Browser
	FirefoxDriver driver;
	String qatechhubUrl = "http://qatechhub.com";
	String facebookUrl = "https://www.facebook.com";

	@Test(priority=0)
	public void invokeBrowser() {

		System.setProperty("webdriver.gecko.driver",
				"C:\\Users\\Saurabh Dhingra\\workspace\\libs\\geckodriver-v0.20.1-win64\\geckodriver.exe");
		driver = new FirefoxDriver();

		driver.manage().window().maximize();

		driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

		driver.get(qatechhubUrl);

		String titleOfThePage = driver.getTitle();
		
		Assert.assertEquals(titleOfThePage, "QA Automation Tools Trainings and Tutorials | QA Tech Hub");

	}

	@Test(priority= 1)
	public void navigateCommands() {
		driver.navigate().to(facebookUrl);

		String currentUrl = driver.getCurrentUrl();

		System.out.println("Current URL :: " + currentUrl);
		driver.navigate().back();

		driver.navigate().forward();

		driver.navigate().refresh();

                driver.quit();
	}

}

 

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: