logo

The best it Trainig Institute In Gurgaon

Write First TestCase in Selenium

    Setting up your Project :
  • Ensure you have a Maven project set up in Eclipse.
  • Add the necessary dependencies to your "pom.xml3" file for Selenium and WebDriverManager.
class-create
    Adding Dependencies
class-create
    Create new test Class :
  • Create a new Java class under "src/test/java" in an appropriate package.
coding
    Writing the selenium Test Script
  • Write the following code in your test class :
  •                               package asc;
    
                                    import org.openqa.selenium.By;
                                    import org.openqa.selenium.WebDriver;
                                    import org.openqa.selenium.chrome.ChromeDriver;
                                    import io.github.bonigarcia.wdm.WebDriverManager;
    
                                    public class LT {
                                        public static void main(String[] args) {
                                            // Set up WebDriver
                                            WebDriverManager.chromedriver().setup();
                                            WebDriver driver = new ChromeDriver();
                                            
                                            // Navigate to the website
                                            driver.get("http://www.saucedemo.com/");
                                            
                                            // Find elements and perform actions
                                            driver.findElement(By.id("user-name")).sendKeys("standard_user");
                                            driver.findElement(By.id("password")).sendKeys("secret_sauce");
                                            driver.findElement(By.xpath("//input[@value='Login']")).click();
                                            
                                            // Close the browser
                                            driver.close();
                                        }
                                    }
                                    
    Running The Test :
  • Run the Project & Output
  • output