Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalTest.PragmaticFinalTest;
- import org.junit.*;
- import org.openqa.selenium.Alert;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.interactions.Actions;
- public class AviabilityProduct {
- public static void aviabilityProductTest(String product, String model){
- AdminLogin.open();
- AdminLogin.login("admin", "parola");
- AdminDashboard.goToProductsPage();
- WebElement isProductEnabled = Browser.driver.findElement(By.name("filter_name"));
- isProductEnabled.clear();
- isProductEnabled.sendKeys(product);
- WebElement filterButton = Browser.driver.findElement(By.linkText("Filter"));
- filterButton.click();
- WebElement message = Browser.driver.findElement(By.className("results"));
- String actualValidationMessage = message.getText();
- String expectedMessage = "Showing 0 to 0 of 0 (0 Pages)";
- //If actualValidationMessage is equal to expected Message, we create new product
- if (actualValidationMessage.contains(expectedMessage)) {
- WebElement insertButton = Browser.driver.findElement(By.linkText("Insert"));
- insertButton.click();
- WebElement productName = Browser.driver.findElement(By.name("product_description[1][name]"));
- productName.clear();
- productName.click();
- productName.sendKeys(product);
- WebElement dataButton = Browser.driver.findElement(By.linkText("Data"));
- dataButton.click();
- WebElement modelProduct = Browser.driver.findElement(By.name("model"));
- modelProduct.sendKeys(model);
- WebElement saveButton = Browser.driver.findElement(By.linkText("Save"));
- saveButton.click();
- WebElement messageForNewProduct = Browser.driver.findElement(By.className("success"));
- String actualMessageForSavedProduct = messageForNewProduct.getText();
- String expectedMessageForSavedProduct = "Success: You have modified products!";
- Assert.assertEquals("The validation messages not expected", expectedMessageForSavedProduct, actualMessageForSavedProduct);
- //In other case we delete this product and make new one
- } else{
- WebElement inputCheckbox = Browser.driver.findElement(By.name("selected[]"));
- inputCheckbox.click();
- WebElement deleteButton = Browser.driver.findElement(By.linkText("Delete"));
- deleteButton.click();
- Alert alert = Browser.driver.switchTo().alert();
- String textOnAlert = alert.getText();
- alert.accept();
- Actions action = new Actions(Browser.driver);
- WebElement catalogList = Browser.driver.findElement(By.linkText("Catalog"));
- catalogList.click();
- WebElement productsInCatalogList = Browser.driver.findElement(By.linkText("Products"));
- productsInCatalogList.click();
- WebElement insertButton = Browser.driver.findElement(By.linkText("Insert"));
- insertButton.click();
- WebElement productName = Browser.driver.findElement(By.name("product_description[1][name]"));
- productName.clear();
- productName.click();
- productName.sendKeys(product);
- WebElement dataButton = Browser.driver.findElement(By.linkText("Data"));
- dataButton.click();
- WebElement modelProduct = Browser.driver.findElement(By.name("model"));
- modelProduct.sendKeys(model);
- WebElement saveButton = Browser.driver.findElement(By.linkText("Save"));
- saveButton.click();
- WebElement messageForNewProduct = Browser.driver.findElement(By.className("success"));
- String actualMessageForSavedProduct = messageForNewProduct.getText();
- String expectedMessageForSavedProduct = "Success: You have modified products!";
- Assert.assertEquals("The validation messages not expected", expectedMessageForSavedProduct, actualMessageForSavedProduct);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement