Sunday, July 14, 2019

Identify number of alerts raised to given username using Selenium Java

Steps used below:
1. Open IE browser
2. Login into IBM Sterling using username & password
3. Click login button
4. Open Alert Console screen
5. Input username in the Search box
6. Click the Search button
7. Fetch number of alerts

package javaselenium;
import java.awt.AWTException;
import java.awt.Robot;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class IdentifyAlertCount {

public static void main(String[] args) throws AWTException {
   
Robot robot = new Robot();

    // Creating a driver object referencing WebDriver interface
        WebDriver driver;
        
        // Setting the webdriver.ie.driver property to its executable's location
        System.setProperty("webdriver.ie.driver", "C:\\Driver\\IEDriverServer.exe");

        // Instantiating driver object
        driver = new InternetExplorerDriver();
        
        // Using get() method to open a webpage
        driver.get("http://localhost:7001/smcfs/console/login.jsp");
        
        // Maximizes the browser window
    driver.manage().window().maximize() ;
        
        // Set value to Username
        driver.findElement(By.name("UserId")).sendKeys("testuser");

        // Set value to Password
        driver.findElement(By.name("Password")).sendKeys("testuser");
        
        // Submit the Form
        driver.findElement(By.name("btnLogin")).submit(); 
        
        // Delay for 3 seconds
        robot.delay(3000);
        
        // Open Alert Console
        driver.get("http://localhost:7001/smcfs/console/exception.search");
        
        // Input - Username to whom the Alerts assigned
        driver.findElement(By.name("xml:/Inbox/User/@Loginid")).sendKeys("mano");
        driver.findElement(By.name("btnSearch")).click();

        // Delay for 1 seconds
        robot.delay(1000);

        // Obtaining value from Retrived records count
        JavascriptExecutor js = (JavascriptExecutor) driver;
        String records = (String) js.executeScript("return document.all['TotalNumRecs'].value");
        
        System.out.println("Total Records:"+records);
               
    }

}

No comments:

Post a Comment

Popular Posts