Advertisement
Atanasov_88

Untitled

Jul 14th, 2016
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package FinalTest.PragmaticFinalTest;
  2.  
  3. import org.junit.*;
  4. import org.openqa.selenium.Alert;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8.  
  9. public class AviabilityProduct {
  10.    
  11.    
  12.     public static void aviabilityProductTest(String product, String model){
  13.        
  14.         AdminLogin.open();
  15.         AdminLogin.login("admin", "parola");
  16.         AdminDashboard.goToProductsPage();
  17.        
  18.         WebElement isProductEnabled = Browser.driver.findElement(By.name("filter_name"));
  19.         isProductEnabled.clear();
  20.         isProductEnabled.sendKeys(product);
  21.         WebElement filterButton = Browser.driver.findElement(By.linkText("Filter"));
  22.         filterButton.click();
  23.        
  24.         WebElement message = Browser.driver.findElement(By.className("results"));
  25.         String actualValidationMessage = message.getText();
  26.         String expectedMessage = "Showing 0 to 0 of 0 (0 Pages)";
  27.                
  28.         //If actualValidationMessage is equal to expected Message, we create new product
  29.         if (actualValidationMessage.contains(expectedMessage)) {
  30.             WebElement insertButton = Browser.driver.findElement(By.linkText("Insert"));
  31.             insertButton.click();
  32.            
  33.             WebElement productName = Browser.driver.findElement(By.name("product_description[1][name]"));
  34.             productName.clear();
  35.             productName.click();
  36.             productName.sendKeys(product);
  37.            
  38.             WebElement dataButton = Browser.driver.findElement(By.linkText("Data"));
  39.             dataButton.click();
  40.            
  41.             WebElement modelProduct = Browser.driver.findElement(By.name("model"));
  42.             modelProduct.sendKeys(model);
  43.             WebElement saveButton = Browser.driver.findElement(By.linkText("Save"));
  44.             saveButton.click();
  45.            
  46.             WebElement messageForNewProduct = Browser.driver.findElement(By.className("success"));
  47.             String actualMessageForSavedProduct = messageForNewProduct.getText();
  48.             String expectedMessageForSavedProduct = "Success: You have modified products!";
  49.             Assert.assertEquals("The validation messages not expected", expectedMessageForSavedProduct, actualMessageForSavedProduct);
  50.            
  51.             //In other case we delete this product and make new one
  52.         } else{
  53.             WebElement inputCheckbox = Browser.driver.findElement(By.name("selected[]"));
  54.             inputCheckbox.click();
  55.             WebElement deleteButton = Browser.driver.findElement(By.linkText("Delete"));
  56.             deleteButton.click();
  57.             Alert alert = Browser.driver.switchTo().alert();
  58.             String textOnAlert = alert.getText();
  59.             alert.accept();
  60.             Actions action = new Actions(Browser.driver);    
  61.             WebElement catalogList = Browser.driver.findElement(By.linkText("Catalog"));
  62.             catalogList.click();
  63.             WebElement productsInCatalogList = Browser.driver.findElement(By.linkText("Products"));
  64.             productsInCatalogList.click();
  65.    
  66.             WebElement insertButton = Browser.driver.findElement(By.linkText("Insert"));
  67.             insertButton.click();
  68.            
  69.             WebElement productName = Browser.driver.findElement(By.name("product_description[1][name]"));
  70.             productName.clear();
  71.             productName.click();
  72.             productName.sendKeys(product);
  73.            
  74.             WebElement dataButton = Browser.driver.findElement(By.linkText("Data"));
  75.             dataButton.click();
  76.            
  77.             WebElement modelProduct = Browser.driver.findElement(By.name("model"));
  78.             modelProduct.sendKeys(model);
  79.             WebElement saveButton = Browser.driver.findElement(By.linkText("Save"));
  80.             saveButton.click();
  81.            
  82.             WebElement messageForNewProduct = Browser.driver.findElement(By.className("success"));
  83.             String actualMessageForSavedProduct = messageForNewProduct.getText();
  84.             String expectedMessageForSavedProduct = "Success: You have modified products!";
  85.             Assert.assertEquals("The validation messages not expected", expectedMessageForSavedProduct, actualMessageForSavedProduct);
  86.         }
  87.  
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement