Showing posts with label web driver. Show all posts
Showing posts with label web driver. Show all posts

Tuesday, March 12, 2019

Data provider in TestNG

 package muttu.test;  
 import org.testng.annotations.DataProvider;  
 import org.testng.annotations.Test;  
 public class DataProviderDemo {  
      @DataProvider(name = "LoginDeatls")  
      public Object[][] getUserDetails() {  
           return new Object[][] { { "uName1", "pwd1" }, { "uName2", "pwd2" } };  
      }  
      @Test(dataProvider = "LoginDeatls")  
      public void Login(String name, String password) {  
           System.out.println(name);  
           System.out.println(password);  
      }  
 }  

Friday, March 8, 2019

Select an Item from the drop-down in selenium webdriver

 package learning;  
 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.support.ui.Select;  
 public class Dropdown {  
      public static void main(String[] args) {  
           System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");  
           WebDriver driver = new ChromeDriver();  
           driver.manage().window().maximize();  
           driver.manage().deleteAllCookies();  
           driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);  
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
           driver.get("https://html.com/attributes/select-size/?utm_source=network%20recirc&utm_medium=Bibblio");  
           //Select dropdown by Select class  
           Select select = new Select(driver.findElement(By.xpath("//select")));  
           //select required item from the above dropdown  
           select.selectByValue("Lesser");  
      }  
 }  

Dealing with modal dialog in selenium Webdriver

 package test.test;  
 import java.util.concurrent.TimeUnit;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 public class ModelDialog {  
      public static void main(String[] args) throws InterruptedException {  
           System.setProperty("webdriver.chrome.driver",  
                     "C:\\Users\\Mutturaj\\Downloads\\chromedriver_win32\\chromedriver.exe");  
           WebDriver driver = new ChromeDriver();  
           driver.manage().window().maximize();  
           driver.manage().deleteAllCookies();  
           driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);  
           driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
           driver.get("https://html.com/input-type-file/");  
           WebElement element = driver.findElement(By.xpath("//*[@id='fileupload']"));  
           JavascriptExecutor jse = (JavascriptExecutor) driver;  
           jse.executeScript("arguments[0].scrollIntoView()", element);  
           element.sendKeys("C:/Users/Mutturaj/Downloads/chromedriver_win32/chromedriver.exe");  
           System.out.println("File Uploaded");  
           // activeElement() method clicks the modal dialog  
           driver.switchTo().activeElement();  
           // Click on the button, here in out case we click on the 'Don't allow'  
           // button  
           driver.findElement(By.linkText("Don't Allow")).click();  
           driver.findElement(By.xpath("//input[@type='submit' and @value='submit']")).click();  
           System.out.println("Submitted");  
      }  
 }