How to create Selenium test cases
Related Product On This Page How to extract trial cases from Business RequirementsMarch 17, 2026 · 8 min read · Tool Comparison
Selenium is one of the most wide secondhand tools for automating web application examine across browsers and platforms. Writing effective Selenium test cases involves place the right exploiter flows, selecting locators, implementing test logic, and ensuring maintainability through best practices. Whether you ’ re screen a login page or a complete checkout stream, structured Selenium tests assist get bugs early and improve test coverage in CI/CD grapevine. This guidebook walk you through the step-by-step process of penning, organizing, and executing Selenium tests to ensure honest and scalable browser automation. All software must undergo before being released. This method tests the application workflow from beginning to end by replicating different user scenarios. The first step in performing an End to End test is to analyze business requirements. A tester take the different user personas involved, aims for, and considers apply automation to accomplish it. The usual process get with the tester canvas the concern requirements to isolate a set of user stories. These user narrative assist represent the business requirements & # 8211; what a someone utilise the product would like to be able to do. This, in twist, helps cater to a serial of user personas, and create a figure of. Once the exam scenario are framed, a set of are followed to frame these scenario into a succession of actions that can help verify a particular functionality. This is what is known as a. To write the first test case, deal a sample business prerequisite & # 8211;Ensure secure user unveiling to a Account. Given that a exploiter attempt to gain introduction to a Browserstack Account could either be a new or an existing user, trial scenarios can be framed around both theRegister and Login pages. For the intention of this article, consider the exploiter persona to be that of a registered exploiter. On view encounter the Browserstack Login page, ask the following questions: All of these test scenario can now be expanded into a set of positive and negative test case. Positive test cases ensure that the ‘ happy-path ’ or expected user journey when the correct data is entered, works as intended. Negative trial cases focalise on invalid actions, often by replicating the input of invalid data or seeking access to an invalid component. In this case, the first test scenario can lead to the development of a positive test case, whereas the rest lead to negative tryout cases. Starting out with Selenium essay? Try BrowserStack Test University and get access to existent devices for a hands-on learning experience.. Build a Selenium test case example based on the first exam scenario. 1. Test Scenario:To authenticate a successful user login on Test Steps: 2. Prerequisites:A registered email ID with a unique username and parole. 3. Browser: Chrome v 86. 4. Test Data: Legitimate username and word. 5. Expected/Intended Results:Once username and password are entered, the web page redirects to the exploiter ’ s dashboard. 6. Existent Results:As Expected 7. Test Status:Pass/Fail: Pass Read More: After configuring the scheme to fulfil exam scripts (as discussed in a previous article on), convert the manual test event into an executable test script. For that, carry out the following steps: Explore each step in point: Step 1 & # 8211;To launch the website in a browser of your choosing, set the scheme properties to the path of the needed driver for the browser. Since this example habituate Google Chrome, it should be set to the. The codification for the same is as follows & # 8211; SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. Step 2 & # 8211;Proceed to maximize the browser for a open picture of test cases be executed using the following command. Step 3 & # 8211;Once the basic job are consummate, execute each step of the manual test case articulated in the previous subdivision. Here is a step-by-step procedure to implement a Selenium test script: Step 1 – The exploiter voyage to Gmail.com Step 2 –In the ’ email ’ field, the exploiter recruit their registered e-mail reference. To perform this step, locate the email field on the Google Sign In variety, and enter the requirement data. Use the ID in Chrome DevTools to identify the necessary elements for the Email field, and store them in a webelement variable. Once the element has be located, perform the requisite action: Read More: Step 3 & # 8211; The user enters the registered password Repeat the same summons for the password field as well Step 4 & # 8211; The exploiter clicks ‘ Sign In ’ Once the e-mail and password web constituent have been located and the actions have been perform, the tester can perform the concluding trust action. In this case, the exploiter clicks ‘Sign In.’ Now, validate the actions performed using affirmation. Assertions assist testers compare the expected and actual results of the actions performed. If these are in sync, the test case is said to have passed. Otherwise, the test case is see to have failed. Read More: The assertion, in this case, is of the general form: The String actual variable throw the post-login value, which is: The method below can help get the expected URL: Thus, the final code will appear something like this: If the examination case surpass, it will retrieve the same else will return as having failed. The last code will be as follows: Selenium and other test automation frameworks help reduce ontogenesis cycle timeframes, avoid repetitive tasks and achieve in a quick and effective manner. But, to get the well-nigh out of Selenium tests, it is necessary to concenter on some best practices when selecting test cases for automation. 1. Prize test suites which offer the highest Return on Investment in damage of cost-saving, increase efficiency, and improving test quality. 2. Identify on what they are meant to do. postulate to be automated. Based on business goals and requirement, automatize the followers: 3. Consider the executing time and prove frequency of these test instance. If one or both of these parameters are high, then it is likely a test automation fabric is required to pen these test cases. Teams can leverage based platforms like BrowserStack that offer a of 3000+ real browsers and device. It empowers teams to run concurrent Selenium tests on coveted existent device-browser combination online. Without the limit of, testers can verify website functionality in. They can accelerate testing time with, and get results faster without compromising on truth. Read More: On BrowserStack, examiner can leverage with a legion of CI/CD tools like Jenkins, Travis, Circle CI, etc. They can also utilize multiple features for more comprehensive testing scenario & # 8211;,,. Following best praxis ensures your Selenium trial cases are reliable, maintainable, and efficient. Here are the key guidelines: Running Selenium tests effectively is key to achieving reliable, scalable, and repeatable exam mechanization for your web applications. By setting up the right environment, choosing suitable browsers and platforms, and integrating with CI/CD line, squad can guarantee quicker feedback and high tryout coverage. Start little, automate critical exploiter flow first, and scale confidently using tool like for real gimmick and cross-browser testing. On This Page # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
How to make Selenium test cases
How to pull test cause from Business Requirements
Writing a test cause using Selenium
Test Management Reimagined with AI
Example of a Test Case in Selenium
Converting a Selenium Test Case to a Test Script
Webdriver driver = new ChromeDriver (); System.setProperty (`` webdriver.chrome.driver '', `` Path of the chrome driver '');
driver.manage.window.maximize ();
Implement test steps
driver.get (`` https: //www.browserstack.com/users/sign_in '');
driver.findElement (By.id (`` user_email_login '')); WebElement username=driver.findElement (By.id (`` user_email_login ''));
username.sendKeys (`` abc @ gmail.com '');
driver.findElement (By.id (`` user_password '')); WebElement password=driver.findElement (By.id (`` user_password '')); password.sendKeys (`` your_password '');
login.click ();
Assert.assertEquals (String existent, String expected);
String actualUrl= '' https: //live.browserstack.com/dashboard '';
String expectedUrl= driver.getCurrentUrl ();
Assert.assertEquals (actualUrl, expectedUrl);
import org.openqa.selenium.By; meaning org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; importation org.openqa.selenium.chrome.ChromeDriver; importation org.testng.Assert; import org.testng.annotations.Test; public class LoginAutomation {@ Test public void login () {System.setProperty (`` webdriver.chrome.driver '', `` path of driver ''); WebDriver driver=new ChromeDriver (); driver.manage () .window () .maximize (); driver.get (`` https: //www.browserstack.com/users/sign_in ''); WebElement username=driver.findElement (By.id (`` user_email_Login '')); WebElement password=driver.findElement (By.id (`` user_password '')); WebElement login=driver.findElement (By.name (`` commit '')); username.sendKeys (`` abc @ gmail.com ''); password.sendKeys (`` your_password ''); login.click (); String actualUrl= '' https: //live.browserstack.com/dashboard ''; String expectedUrl= driver.getCurrentUrl (); Assert.assertEquals (expectedUrl, actualUrl);}}How to Select Test Cases for Selenium Automation
Best Practices for Writing Selenium Test Cases
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously