package org.camunda.bpm.tasklist.test;


import org.camunda.bpm.TestProperties;
import org.camunda.bpm.util.SeleniumScreenshotRule;
import org.camunda.bpm.util.TestUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.Rule;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


/**
 * @author drobisch
 */
public class TasklistIT {

  protected static WebDriver driver = new FirefoxDriver();
  protected String appUrl;

  protected TestProperties testProperties;
  private TestUtil testUtil;

  @Rule
  public SeleniumScreenshotRule screenshotRule = new SeleniumScreenshotRule(driver);

  @Before
  public void before() throws Exception {
    testProperties = new TestProperties(48080);
    appUrl = testProperties.getApplicationPath("/camunda/app/tasklist");
    
    testUtil = new TestUtil(testProperties);
//    testUtil.createInitialUser("admin", "admin", "Mr.", "Admin");
  }

  @Test
  public void testLogin() {
    driver.get(appUrl + "/#/login");

    WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement user = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[type=\"text\"]")));
    user.sendKeys("demo");

    WebElement password= wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[type=\"password\"]")));
    password.sendKeys("demo");

    WebElement submit = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[type=\"submit\"]")));
    submit.submit();

    boolean found = wait.until(ExpectedConditions.textToBePresentInElement(By.cssSelector("td"), "Assign Approver"));
  }

  @After
  public void after() {
//    testUtil.deleteUser("admin");
    testUtil.destroy();
  }

  @AfterClass
  public static void cleanup() {
    driver.close();
  }
}

@@ -557,16 +557,69 @@
 rWait;%0A%0A
+import static junit.framework.Assert.assertNotNull;%0A%0A
 %0A/**%0A * 
@@ -1806,15 +1806,91 @@
     
-boolean
+String xpathExpression = %22//td%5Bcontains(text(),'Assign Approver')%5D%22;%0A    WebElement
  fou
@@ -1928,73 +1928,85 @@
 ons.
-textToBeP
+p
 resen
-tIn
+ceOf
 Element
-(By.cssSelector(%22td%22), %22Assign Approver%22)
+Located(By.xpath(xpathExpression)));%0A    assertNotNull(found
 );%0A 

fix lookup of correct taskName element in TasklistIT