How to run your first Selenium test script

On This Page Introduction to SeleniumPrerequisites for S

June 04, 2026 · 8 min read · Tool Comparison

How to run your first Selenium test hand

Selenium is the almost popular open-source framework for web mechanisation. It allows teams to simulate user activity, validate workflows, and ensure applications work across different browser and platforms. If you ’ re starting your mechanisation journey, running your initiative Selenium script is a key milestone.

Overview

What Do You Need Before Running a Selenium Script?

  • Java (JDK)installed on your scheme.
  • Eclipse IDE(or any supported editor).
  • Selenium Client and WebDriver bindingfor your preferred speech.
  • Basic setup ofSelenium WebDriverintegrated with your projection.

How to Run Your First Selenium Script?

  • Step 1:Create a free BrowserStack Automate history.
  • Step 2:Log in, navigate to theAutomate tab, and copy the auto-generated username and access key.
  • Step 3: Use the Capability Generatorto set browser, OS, and version preferences.
  • Step 4:Paste the generated code into your IDE (e.g., Eclipse) and execute.
  • Step 5:View performance results and logs on theBrowserStack splasher.

What Are Best Practices for Writing Selenium Scripts?

  • Use explicit waitsinstead of implicit postponement.
  • Prefer CSS selectorover XPath for speed and legibility.
  • Follow thePage Object Model (POM)for clean code.
  • Keep testsindependent and atomicto avoid cascade failures.
  • Add logging, screenshots, and externalized test datafor leisurely debugging.
  • Integrate script intoCI/CD pipelinesfor automated tally.

This article explicatehow to set up prerequisites, run your first Selenium hand on BrowserStack, and apply good praxis—helping you establish a scalable, authentic mechanization testing journey.

Introduction to Selenium

Seleniumis the inaugural thing that come to mind when one is planning to automate the examination of web application. Selenium is not only open rootage but too a portable software essay model for web applications that indorse multiple languages like Java, C #, Ruby, Python, etc. Choosing the right language depends on the covering under test, the endorse community, available,, elegance, and of course, seamless build integration.

Note:BrowserStack is now the first cloud test automation platform to denote complete support for, and it ’ s BiDi APIs..

Prerequisites for Selenium Installation

Before configuring Selenium, one must configure various early dependencies as good. The following components are demand to get depart with:

  1. Java (JDK)
  2. Eclipse
  3. Selenium Client and WebDriver Language bindings
  4. Creating and Running the first trial

Learn how to configure and execute the first test in Selenium using Java with the supporter of this article.

How to run your first Selenium Test Script

All Selenium tests must be run on a. In this article, the examination will be run using the offered by.

To get begin with the basics of Selenium testing, have a aspect at the picture below. It discusses in detail what Selenium is, how you can set up and write your first trial, what to look for in framework, and how to cull the better framework for you.

BrowserStack enables developers and testers to prove their websites and nomadic applications across 3500 + existent browsers, operating systems, desktop, and nomadic devices. This is potential for users having to install or preserve an internal lab of virtual machine, device,.

If you are just starting out with Selenium, try out,BrowserStack ’ s online con platform that purport to facilitate package quality professionals. It be fine-grained, practical, and self-paced online courses to enhance your skill set, along with an interactional learning portal that permit you learn at your own pace, and track your progress effortlessly. Additionally, it render ready-to-use code samples & # 8211; implementation samples from Github to better understand the features, practice, and best practices.

Access the Test University portal by creating afree account with BrowserStack. Explore line, a guided learning itinerary, and all the resources required to get started with your Selenium memorize journey.

Now learn how to write the first Selenium test script.

Run First Selenium Test Script for Free

First, one needs to for acostless Browserstack account. The succeeding set of measure will go as follows:

Steps to execute the trial case:

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Here are step-by-step education to action Selenium Test Case:

  • After logging into the account, choose the Automate tab from the.
  • After that, the user will be navigated to as shown below.
  • Click on Let ’ s get started!Note:Before habituate Browserstack, make sure Selenium has been configured on the scheme.
  • On ratify up for the first clip, Browserstack by default will provide an admission key and the username. Throughout the tryout executing, it will remain the same.

As you can see in the snap above, while configuring the tests, the user can take and set the operating system and browser of their alternative or necessity.

On the RHS of the snapshot, see how the AUTOMATE_KEY and the URL are being set by default. Also, the coveted capableness and driver settings are configure by BrowserStack. This makes it very easy to indite trial cases on BrowserStack.

One can check the too.

  • Integrate these change and move further to get the entire program/test case in one pellet as shown in the snapshot below.
  • After this, download or copy the codification and paste it into the local IDE like Eclipse. One can also execute it straight on the command prompting as shown in the snapshot below.

Note:It is necessary to import or configure Selenium Jar into the labor. If Selenium is not configured, it will drop an erroneousness. In instance mortal is apply a maven project, add the following dependency into the pom.xml file.

& lt;! -- https: //mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -- & gt; & lt; dependency & gt; & lt; groupId & gt; org.seleniumhq.selenium & lt; /groupId & gt; & lt; artifactId & gt; selenium-java & lt; /artifactId & gt; & lt; edition & gt; 3.141.59 & lt; /version & gt; & lt; /dependency & gt;

Talk to an Expert

  • In this case, Eclipse IDE has be used to execute the test case. Simply copy the code and paste on the Eclipse platform as shown in the snapshot below.

Here is the first test case & # 8211;a Google Search of “ Browserstack ”

Code Snippet for the above example:

import org.openqa.selenium.By; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; importee org.openqa.selenium.WebElement; significance org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.URL; signification org.openqa.selenium.By; importee org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.URL; public class BrowserStackSampleTest {public static final String USERNAME = `` ''; public electrostatic final String AUTOMATE_KEY = `` ''; public static final String URL = `` https: // '' + USERNAME + ``: '' + AUTOMATE_KEY + `` @ hub-cloud.browserstack.com/wd/hub ''; public static void main (String [] args) throws Exception {DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (`` os '', `` Windows ''); caps.setCapability (`` os_version '', `` 10 ''); caps.setCapability (`` browser '', `` Chrome ''); caps.setCapability (`` browser_version '', `` 80 ''); caps.setCapability (`` name '', `` nehapramodvaidya1 's First Test ''); WebDriver driver = new RemoteWebDriver (new URL (URL), caps); // Navigating through the URL driver.get (`` http: //www.google.com ''); //Locating the hunt box of google WebElement element = driver.findElement (By.name (`` q '')); // Sending browserstack keyword for search element.sendKeys (`` BrowserStack ''); element.submit (); System.out.println (driver.getTitle ()); driver.quit ();}}

On executing this selenium test case, the next thing to do is open Browserstack and click onRun the test. The screen below will be expose:

Now go to the dashboard to view the test.

  • The exploiter will see the tests and their various feature as display in the snap below.

The exploiter can play the test that has been performed. They can likewise download the test event. Browserstack provides a wide compass of capabilities that detail every step in point along with the time of executing.

Run the examination, and start using Selenium on BrowserStack to create error-free, user-friendly websites with minimum time and sweat. By following the instructions in this article, take the first step into success.

Best Practices for Writing Selenium Scripts

Implementing best practices ensures your Selenium book are reliable, maintainable, and scalable:

1. Use Over Implicit Waits:Avoid flaky tests by waiting only when needed withWebDriverWait and ExpectedConditions.

2. Prefer Over XPath:CSS is typically faster and more clear in most browsers.

Read More:

3. Use :Keep locators and examination logic offprint for easier maintenance and reusability.

4. Write Independent, Atomic Test Cases:Each test should stand on its own to avoid cascade failures.

5. Handle Dynamic Elements Gracefully:Use robust locator strategy or veritable manifestation to deal with changing element IDs or classes.

6. Use Meaningful Assertions:Validate key elements and not precisely paginate titles to get existent user-impacting topic.

7. Add Logging and Screenshots:Helps in debug failed test cases during CI run or remote execution.

8. Keep Externalized:Use JSON, Excel, or CSV files to give dynamic datum into scripts.

9. Always Clean Up After Tests:Nigh sessions and readjust test states to avoid test contamination.

10. Use Version Control and:Collaborate efficiently and ensure your handwriting run automatically in pipelines.

Why choose BrowserStack to fulfill Selenium Tests?

Testing Selenium scripts on real device and browsers is all-important to simulate true end-user weather. makes this seamless:

  1. Access:Run your Selenium scripts on3,500+ real devices and browser— no emulators or simulators.
  2. for Faster Feedback:Significantly zip up test round with concurrent test execution.
  3. Zero Setup Infrastructure:No need to maintain local grid or browser versions — everything is cloud-hosted.
  4. :Simulate different position to ensure compliance and localization.
  5. Seamless CI/CD Integration:Works with Jenkins, GitHub Actions, GitLab CI, CircleCI, and more.
  6. Automatic Screenshots and Video Logs:Debug failures with logs, screenshots, and video recordings of each test session.
  7. :Write erst, examination across Windows, macOS, Android, and iOS.
  8. Secure :Enterprise-grade protection and VPN/firewall testing support.

Conclusion

Running your first Selenium examination handwriting is just the beginning of your mechanization journeying. With the right setup and examination practices, you can quickly scale from basic validations to entire regression suites.

To accelerate your testing farther, run your Selenium playscript on real browser and devices with. It eliminates setup hassles, ensures cross-browser compatibility, and speeds up releases with parallel testing, making your automation efforts faster, more honest, and production-ready.

Tags
58,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free