Guest User

TestNg

a guest
Dec 11th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. package POM_NEW;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6.  
  7.  
  8. public class POM_Object_Repository {
  9.     WebDriver driver;
  10.    
  11.     //constructor
  12.     public POM_Object_Repository(WebDriver driver) {
  13.         this.driver = driver;
  14.     }
  15.  
  16.     public void OpenBrowser(){
  17.        
  18.         driver.manage().window().maximize();
  19.        
  20.     }
  21.    
  22.     public void LaunchApplication(){
  23.        
  24.         driver.get("https://opensource-demo.orangehrmlive.com/");
  25.        
  26.     }
  27.    
  28.     public WebElement UserName(){
  29.         WebElement user=driver.findElement(By.xpath("//input[@id='txtUsername']"));
  30.         return user;
  31.        
  32.     }
  33.  
  34.    
  35.     public WebElement Password(){
  36.         WebElement pass=driver.findElement(By.xpath("//input[@id='txtPassword']"));
  37.         return pass;
  38.        
  39.     }
  40.    
  41.     public WebElement Click(){
  42.         WebElement click=driver.findElement(By.xpath("//input[@id='btnLogin']"));
  43.         return click;
  44.        
  45.     }
  46.    
  47.     public void CloseBrowser(){
  48.         driver.close();
  49.     }
  50.    
  51.     public WebElement Performance(){
  52.         WebElement performance=driver.findElement(By.xpath("//*[@id='menu__Performance']/b"));
  53.         return performance;
  54.     }
  55.        
  56.     public WebElement Configure(){
  57.         WebElement configure=driver.findElement(By.xpath("//*[@id='menu_performance_Configure']"));
  58.         return configure;
  59.     }
  60.        
  61.     public WebElement KPIs(){
  62.         WebElement kpis=driver.findElement(By.xpath("//*[@id='menu_performance_searchKpi']"));
  63.         return kpis;
  64.     }
  65.    
  66.     public WebElement Add(){
  67.         WebElement add=driver.findElement(By.xpath("//*[@id='btnAdd']"));
  68.         return add;
  69.     }
  70.    
  71.  
  72. }
  73. ------------------------------------------------------------------------------------------------------------------
  74.  
  75.  
  76. package POM_NEW;
  77.  
  78. import org.testng.annotations.Test;
  79. import org.testng.annotations.DataProvider;
  80. import org.testng.annotations.BeforeClass;
  81. import org.openqa.selenium.WebDriver;
  82. import org.openqa.selenium.WebElement;
  83. import org.openqa.selenium.firefox.FirefoxDriver;
  84. import org.testng.annotations.AfterClass;
  85.  
  86. public class POM_TestNG_KeyAddDelete {
  87.    
  88.     WebDriver driver;
  89.     POM_Object_Repository por;
  90.    
  91.    
  92.     @Test(dataProvider = "UserName")
  93.       public void UserName(String UserName) throws InterruptedException {
  94.          
  95.           WebElement user=por.UserName();
  96.           user.sendKeys(UserName);
  97.       }
  98.      
  99.          
  100.           @Test(dataProvider = "Password")
  101.           public void password(String Password) {
  102.          
  103.           WebElement pass=por.Password();
  104.           pass.sendKeys(Password);
  105.          
  106.           WebElement click=por.Click();
  107.           click.click();
  108.          
  109.           //verification
  110.          
  111.           String ExpVal="OrangeHRM";
  112.           String ActVal=driver.getTitle();
  113.           System.out.println("Verification :"+ActVal.equals(ExpVal));
  114.          
  115.          
  116.       }
  117.     @Test(priority=2,dataProvider = "KPIs")
  118.     public void Navigate() throws InterruptedException{
  119.        
  120.         WebElement performance=por.Performance();
  121.         performance.click();
  122.        
  123.         Thread.sleep(5000);
  124.        
  125.         WebElement configure=por.Configure();
  126.         configure.click();
  127.        
  128.         Thread.sleep(5000);
  129.        
  130.         WebElement kpis=por.KPIs();
  131.         kpis.click();
  132.        
  133.         Thread.sleep(5000);
  134.        
  135.         WebElement add=por.Add();
  136.         add.click();
  137.        
  138.        
  139.     }
  140.      
  141.  
  142.  
  143.     @DataProvider
  144.       public Object[][] UserName() {
  145.         return new Object[][] {
  146.           new Object[] { "Admin" },
  147.           //new Object[] { 2, "b" },
  148.         };
  149.       }
  150.      
  151.       @DataProvider
  152.       public Object[][] Password() {
  153.         return new Object[][] {
  154.           new Object[] { "admin123" },
  155.           //new Object[] { 2, "b" },
  156.         };
  157.       }
  158.  
  159.   @BeforeClass
  160.   public void beforeClass() throws InterruptedException {
  161.      
  162.       driver=new FirefoxDriver();
  163.       por=new POM_Object_Repository(driver);
  164.      
  165.       por.OpenBrowser();
  166.       por.LaunchApplication();
  167.       por.UserName();
  168.       por.Password();
  169.       por.Click();
  170.      
  171.       por.Performance();
  172.      
  173.   }
  174.  
  175.   @AfterClass
  176.   public void afterClass() {
  177.       por.CloseBrowser();
  178.   }
  179.  
  180. }
Add Comment
Please, Sign In to add comment