Created
May 1, 2018 20:19
-
-
Save O5ten/01e4aa9e6db8e115ca11f05ae25679ff to your computer and use it in GitHub Desktop.
Remote Grid Selenium TestBase
This file contains hidden or 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 framework; | |
import static framework.Constants.BROWSER_CAPABILIITY; | |
import static framework.Constants.ENABLE_VIDEO; | |
import static framework.Constants.ENABLE_VNC; | |
import static framework.Constants.NAME; | |
import static framework.Constants.THIRTY; | |
import static java.util.concurrent.TimeUnit.SECONDS; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.List; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Rule; | |
import org.junit.rules.TestName; | |
import org.openqa.selenium.Proxy; | |
import org.openqa.selenium.remote.CapabilityType; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class SeleniumTestBase { | |
@Rule | |
public TestName testInfo = new TestName(); | |
private String currentTestName = ""; | |
protected RemoteWebDriver browser; | |
protected List<Page> pagesToInitialize; | |
private URL seleniumGrid; | |
@After | |
public void tearDown() { | |
this.browser.quit(); | |
System.out.println("Recording at http://localhost:4444/video/" + currentTestName + ".mp4"); | |
} | |
@Before | |
public void setup() throws MalformedURLException { | |
System.out.println("Running Selenium Test: " + testInfo.getMethodName()); | |
this.seleniumGrid = new URL("http://localhost:4444/wd/hub"); | |
this.currentTestName = this.getClass().getSimpleName() + "-" + testInfo.getMethodName(); | |
this.browser = getBrowserSession("chrome"); | |
this.pagesToInitialize.forEach(p -> p.configure(this.browser)); | |
} | |
private RemoteWebDriver getBrowserSession(String browser) { | |
DesiredCapabilities abilities = new DesiredCapabilities(); | |
abilities.setCapability("name", testInfo.getMethodName()); | |
abilities.setCapability("enableVNC", true); | |
abilities.setCapability("enableVideo", true); | |
abilities.setCapability("videoName", this.currentTestName + ".mp4"); | |
abilities.setCapability("browser", browser); | |
RemoteWebDriver driver = new RemoteWebDriver(seleniumGrid, abilities); | |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
return driver; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment