Skip to content

Instantly share code, notes, and snippets.

@fmarot
Created June 25, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmarot/9829c973e8fe6a676267390dc3fc5406 to your computer and use it in GitHub Desktop.
Save fmarot/9829c973e8fe6a676267390dc3fc5406 to your computer and use it in GitHub Desktop.
monitor availability of KIMSUFI KS-2
@Grab('org.eclipse.jetty.aggregate:jetty-server:8.1.19.v20160209')
@Grab('org.eclipse.jetty.aggregate:jetty-servlet:8.1.19.v20160209')
@Grab('javax.servlet:javax.servlet-api:3.0.1')
@Grab('org.seleniumhq.selenium:selenium-api:3.5.3')
@Grab('org.seleniumhq.selenium:selenium-remote-driver:3.5.3')
@Grab('org.seleniumhq.selenium:selenium-server:3.5.3')
@Grab('junit:junit:4.12')
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.By.ByXPath
import java.util.concurrent.TimeUnit;
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
try {
driver.get("https://www.kimsufi.com/fr/commande/kimsufi.xml?reference=1801sk13");
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
// with * we are doing tag indepenedent search. If you know the tag, say it's a `div`, then //div[contains(text(),'Text To find')] can be done
By byXpath = By.xpath("//*[contains(text(), 'de paiement')]");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byXpath));
println "myDynamicElement = ${(myDynamicElement == null)}"
println "Will call Kimsufi IFTTT webhook"
def url = "https://maker.ifttt.com/trigger/KIMSUFI/with/key/m-f35znkudBVIK4MUwa4T"
def data = new URL(url).getText()
println data
} catch (org.openqa.selenium.TimeoutException e) {
println "Exception was expected: 1801sk13 still not available..."
} finally {
driver.quit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment