Last active
August 14, 2019 09:27
-
-
Save upgundecha/2ff6fe2c4daf65156ef2c3b62e780f33 to your computer and use it in GitHub Desktop.
Selenium test for SAP Fiori UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sapfioritrial.test; | |
import org.junit.After; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import java.util.UUID; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* Created by upgundecha on 07/03/17. | |
*/ | |
public class SampleTest { | |
WebDriver driver; | |
private By agreeButton = By.xpath("//button//span[text()='I agree']"); | |
private By myTasksTile = By.xpath("//div[contains(@id, 'tile') and contains(@title,'My Tasks')]"); | |
private By addTaskButton = By.xpath("//button[contains(@id,'showEmptyTask')]"); | |
private By taskDescription = By.xpath("//textarea[contains(@id,'descInput-inner')]"); | |
private By saveButton = By.xpath("//button//span[text()='Save']"); | |
private By taskTile = By.xpath("//span[@class='sapMOHTitle']//span[contains(@id,'titleText')]"); | |
@Before | |
public void setUp() { | |
driver = new ChromeDriver(); | |
driver.manage().window().maximize(); | |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
driver.get("https://www.sapfioritrial.com/sites?helpset=trial&sap-client=001"); | |
} | |
@After | |
public void tearDown() { | |
driver.close(); | |
driver.quit(); | |
} | |
@Test | |
public void createTask() throws Exception { | |
// accpet terms & conditions | |
waitForElementLocatedBy(agreeButton); | |
driver.findElement(agreeButton).click(); | |
// click on My Tasks Tile | |
driver.findElement(myTasksTile).click(); | |
sleep(5000); | |
// click on Add Task button ( + icon) | |
driver.findElement(addTaskButton).click(); | |
waitForElementLocatedBy(taskDescription); | |
// enter description - in this example a random string | |
// and click on Save button | |
String desc = UUID.randomUUID().toString(); | |
driver.findElement(taskDescription).sendKeys(desc); | |
driver.findElement(saveButton).click(); | |
sleep(5000); | |
// check the next dialog displays the newly added Task description | |
Assert.assertEquals(desc, driver.findElement(taskTile).getText()); | |
} | |
public void sleep(long duration) { | |
try { | |
Thread.sleep(duration); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void waitForElementLocatedBy(By locator) { | |
new WebDriverWait(driver, 30) | |
.until(ExpectedConditions.presenceOfElementLocated(locator)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment