Skip to content

Instantly share code, notes, and snippets.

@moinuddin14
Created December 23, 2019 08:01
Show Gist options
  • Save moinuddin14/2a03cbc111d9836224c1afd6a467331e to your computer and use it in GitHub Desktop.
Save moinuddin14/2a03cbc111d9836224c1afd6a467331e to your computer and use it in GitHub Desktop.
Selenium AI with Test AI Classifier
import ai.test.classifier_client.ClassifierClient;
import org.hamcrest.collection.IsCollectionWithSize;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
public class Edition101_AI_For_Selenium {
private RemoteWebDriver driver;
private ClassifierClient classifier;
@Before
public void setUp() throws MalformedURLException {
// driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
// new ChromeOptions());
driver = new ChromeDriver();
classifier = new ClassifierClient("127.0.0.1", 50051);
}
@After
public void tearDown() throws InterruptedException {
if (driver != null) {
driver.quit();
}
if (classifier != null) {
classifier.shutdown();
}
}
@Test
public void testClassifierClient() throws Exception {
driver.get("https://test.ai");
List<WebElement> els = classifier.findElementsMatchingLabel(driver, "twitter");
Assert.assertThat(els, IsCollectionWithSize.hasSize(1));
els.get(0).click();
Assert.assertEquals(driver.getCurrentUrl(), "https://twitter.com/testdotai");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment