TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

Run Selenium Test in Google Chrome Browser

Introduction

In this article, we will run a sample selenium test in the Google Chrome browser. To run the test in Chrome we need to set the system property to the path of chrome driver as shown below:

Environment:

  • Google Chrome,
  • Windows 10 Operating System

Download Chrome Browser

Steps to Download  Chrome are listed out here:

(https://www.testingdocs.com/questions/how-to-download-chrome-browser-on-windows/)

System.setProperty(“webdriver.chrome.driver”, “chromedriver.exe”);

Sample Code

public class ChromeBrowserExample {
 private WebDriver driver;

@Test
 public void sampleTest() {
 driver.get("https://www.google.com");
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 Assert.assertEquals(driver.getTitle(), "Google", 
"I'm verifying window title here in this test");

}

@BeforeClass
 public void beforeClass() {
 System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
 driver = new ChromeDriver();
 }

@AfterClass
 public void afterClass() {
 if(driver != null)
 {
 driver.quit();
 }
 }

}

 


Explanation

The above sample TestNG test shown, opens the chrome browser with Google search page. It waits for 30 sec implicitly and verifies the title of the window. The before class annotated method initializes the chrome driver

Test annotated method navigates to google search home page. The after class annotated method kills the driver session at the end.

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Related Posts

Windows 10 Settings

Selenium /

Add Microsoft Webdriver on Windows OS

Download Selenium Components

Selenium /

Getting Started with Selenium Webdriver

LambdaTest Testing Cloud SaaS Platform

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

SauceLabs Website

Selenium /

Run an Example Test on SauceLabs

‹ Selenium3 : Marionette and GeckoDriver Example› Common Exceptions in Webdriver Tests

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com