package ca.corefacility.bioinformatics.irida.ria.integration.pages.remoteapi;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage;

public class CreateRemoteAPIPage extends AbstractPage {
	private static final Logger logger = LoggerFactory.getLogger(CreateRemoteAPIPage.class);

	private final String CREATE_PAGE = "remote_api/create";
	public static String SUCCESS_PAGE = "remote_api/\\d+";

	public CreateRemoteAPIPage(WebDriver driver) {
		super(driver);
		get(driver, CREATE_PAGE);
	}

	public void createRemoteAPIWithDetails(String name, String serviceURI, String clientID, String clientSecret) {
		logger.trace("Creating client with name " + name);

		driver.findElement(By.id("name")).sendKeys(name);
		driver.findElement(By.id("clientSecret")).sendKeys(clientSecret);
		driver.findElement(By.id("clientId")).sendKeys(clientID);
		driver.findElement(By.id("serviceURI")).sendKeys(serviceURI);

		WebElement submit = driver.findElement(By.id("create-remoteapi-submit"));
		submit.click();
	}

	public boolean checkSuccess() {
		if (driver.getCurrentUrl().matches(BASE_URL + SUCCESS_PAGE)) {
			return true;
		} else {
			return false;
		}
	}
}

@@ -1225,95 +1225,152 @@
 %7B%0A%09%09
-if (driver.getCurrentUrl().matches(BASE_URL + SUCCESS_PAGE)) %7B%0A%09%09%09return true;%0A%09%09%7D else
+try %7B%0A%09%09%09// if there's a remove button, we succeeded!%0A%09%09%09driver.findElement(By.id(%22remove-btn%22)); %0A%09%09%09return true;%0A%09%09%7D catch (final Exception e)
  %7B%0A%09

Change the way that we're testing for success on creating a remote API.