Ananta
Ananta Almost a Computer Engineer, author of Go Woogle, I write about tech and tutorials.

3. First Selenium Test


3. First Selenium Test

How to Open a Website in Chrome Browser using Selenium

  1. Create a new class in source folder

Alt

  1. Name it and Click Finish check public static void main(String[] args) option so that you do not need to type it manually. You can completely avoid it in JUnit testing since, it is not required in JUnit Test cases.

Alt

  1. Code

As you can see I have added comments to help you understand code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class openWebsite {

	public static void main(String[] args) {
		System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe"); //Driver path
		WebDriver driver = new ChromeDriver();
		driver.get("https://gowoogle.com"); //URL that will open in chrome
		driver.manage().window().maximize(); //Maximizes Browser Window
	}

}

Please save the file name as openWebsite.java because Java is case sensitive and filename and class name must be same. Here’s the gist version.

Alt

  1. Run as Java Application. This can be done by mulltiple ways I find Right Click Run as > Java Application as my go to method to run specific java files.

Alt

  1. Console will show execution progress.

Alt

  1. Website will Open in Chrome Browser just as web programmed it.

Alt

  1. Browser Window will Maximize.

Alt

Github Repo

Next Article to learn How to Write Your First JUnit Test