3. First Selenium Test
How to Open a Website in Chrome Browser using Selenium
- Create a new class in source folder
- Name it and Click
Finish
checkpublic 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.
- 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.
- 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.
- Console will show execution progress.
- Website will Open in Chrome Browser just as web programmed it.
- Browser Window will Maximize.