本文整理匯總了Java中org.openqa.selenium.phantomjs.PhantomJSDriver.get方法的典型用法代碼示例。如果您正苦於以下問題:Java PhantomJSDriver.get方法的具體用法?Java PhantomJSDriver.get怎麽用?Java PhantomJSDriver.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openqa.selenium.phantomjs.PhantomJSDriver
的用法示例。
在下文中一共展示了PhantomJSDriver.get方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onTrigger
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
DesiredCapabilities DesireCaps = new DesiredCapabilities();
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, context.getProperty(DRIVER_LOCATION).getValue());
driver = new PhantomJSDriver(DesireCaps);
FlowFile flowFile = session.create();
try {
driver.get(url);
(new WebDriverWait(driver, timeout)).until(
ExpectedConditions.visibilityOfElementLocated(getExpectedCondition(selectorType, selector))
);
final byte[] page = formatToXHtml(driver.getPageSource(), StandardCharsets.UTF_8);
flowFile = session.write(flowFile, outputStream -> outputStream.write(page));
session.transfer(flowFile, REL_SUCCESS);
} catch (Exception e) {
flowFile = session.write(flowFile, outputStream -> outputStream.write(e.getMessage().getBytes()));
session.transfer(flowFile, REL_FAILURE);
} finally {
driver.quit();
}
session.getProvenanceReporter().create(flowFile);
}
示例2: testSeleniumGhostDriver
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Test
public void testSeleniumGhostDriver() {
File phantomjs = Phanbedder.unpack();
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());
PhantomJSDriver driver = new PhantomJSDriver(dcaps);
try {
driver.get("https://www.google.com");
WebElement query = driver.findElement(By.name("q"));
query.sendKeys("Phanbedder");
query.submit();
Assertions.assertThat(driver.getTitle()).contains("Phanbedder");
} finally {
driver.quit();
}
}
示例3: setup
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Before
public void setup() throws MalformedURLException {
String webAppUrl = System.getProperty(WEBAPP_URL);
System.setProperty("SELENIUM_STARTING_URL", "http://127.0.0.1:8888/D3Demo.html?gwt.codesvr=127.0.0.1:9997");
// separate localhost and saucelabls/cloudbees env
if (System.getProperty(RUN_SELENIUM_LOCALHOST) != null) {
// ensure the Firefox with default profile is loaded
// in order to use the Firefox instance with GWT dev plugin
System.setProperty("webdriver.firefox.profile", "default");
driver = new FirefoxDriver();
webAppUrl = "http://127.0.0.1:8888/D3Demo.html?gwt.codesvr=127.0.0.1:9997";
} else {
driver = new PhantomJSDriver();
webAppUrl = "http://127.0.0.1:8080/D3Demo.html";
}
Dimension size = new Dimension(1920, 1080);
driver.manage().window().setSize(size);
driver.get(webAppUrl);
}
示例4: testWithHeadlessBrowsers
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Test
public void testWithHeadlessBrowsers(HtmlUnitDriver htmlUnit,
PhantomJSDriver phantomjs) {
htmlUnit.get("https://bonigarcia.github.io/selenium-jupiter/");
phantomjs.get("https://bonigarcia.github.io/selenium-jupiter/");
assertTrue(htmlUnit.getTitle().contains("JUnit 5 extension"));
assertNotNull(phantomjs.getPageSource());
}
示例5: saveScreenshotForHtmlUnit
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
/**
* Screenshooter for HTMLUnit. It saves the html source to disk following the
* same pattern as the screenshot path. The HTMLUnit session is transfered to
* PhantomJs, which takes the screenshot, and is destroyed. The original
* driver is not destroyed
*
* Note: Javascript events, current page changes, etc.. are not saved and are
* not captured in the screenshots taken.
*
* @param path
* - where to save the file. This assumes a png file will be
* generated
* @param baseUrl
* - used to transfer the cookies to the phantomjs driver properly.
*
* @see #getPhantomJsWebDriver()
*/
public void saveScreenshotForHtmlUnit(String path, String baseUrl)
{
final WebDriver driver = this.get();
if (!(driver instanceof HtmlUnitDriver)) {
LOG.warn("Wrong driver called screenshooter for HTMLUnit driver, default to regular screenshooter");
this.saveScreenshotAs(path);
return;
}
PhantomJSDriver phantomJs = (PhantomJSDriver) getPhantomJsWebDriver();
try {
phantomJs.get(baseUrl);
String url = driver.getCurrentUrl();
LOG.debug("Url: {}", url);
for (Cookie cookie : driver.manage().getCookies()) {
LOG.debug("Cookie: {}", cookie.toString());
phantomJs.manage().addCookie(cookie);
}
phantomJs.get(url);
// set current thread to phantomjs, and take screenshot in the default way
this.set(phantomJs);
LOG.debug("HTML Screenshot taken: {}", this.saveScreenshotAs(path));
}
finally {
// set back original driver for this thread
this.set(driver);
phantomJs.close();
phantomJs.quit();
}
}
示例6: prepare
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
/**
* 初始化配置 PhantomJS Driver.
*
* @param url 目標URL
* @param addedCookie 添加 cookie
* @return 初始化過的 PhantomJS Driver
*/
public static PhantomJSDriver prepare(String url, Cookie addedCookie, Integer width, Integer height) {
// chrome driver maybe not necessary
// download from https://sites.google.com/a/chromium.org/chromedriver/downloads
// System.setProperty("webdriver.chrome.driver",
// DirUtils.RESOURCES_PATH.concat(
// PropUtils.getInstance().getProperty("html.exporter.webdriver.chrome.driver")));
DesiredCapabilities phantomCaps = DesiredCapabilities.chrome();
phantomCaps.setJavascriptEnabled(true);
phantomCaps.setCapability("phantomjs.page.settings.userAgent",
PropUtils.getInstance().getProperty("html.exporter.user.agent"));
PhantomJSDriver driver = new PhantomJSDriver(phantomCaps);
driver.manage().timeouts().implicitlyWait(Integer.valueOf(PropUtils.getInstance()
.getProperty("html.exporter.driver.timeouts.implicitly.seconds")), TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(Integer.valueOf(PropUtils.getInstance()
.getProperty("html.exporter.driver.timeouts.page.load.seconds")), TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(Integer.valueOf(PropUtils.getInstance()
.getProperty("html.exporter.driver.timeouts.script.seconds")), TimeUnit.SECONDS);
if (width == null || height == null) driver.manage().window().maximize();
else driver.manage().window().setSize(new Dimension(width, height));
if (addedCookie != null) driver.manage().addCookie(addedCookie);
driver.get(url);
// try {
// // timeout is not work, so fix it by sleeping thread
// Thread.sleep(Integer.valueOf(PropUtils.getInstance()
// .getProperty("html.exporter.driver.timeouts.implicitly.seconds")) * 1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
return driver;
}
示例7: createDriver
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Before
public void createDriver() {
driver = new PhantomJSDriver();
indexPage = new IndexPage( driver );
indexPage.getMainMenu().openRegisterForm();
registerSteps = new RegisterSteps( driver );
registerSteps.register( testName, testLogin, testPassword );
driver.get(NEW_POST_URL);
}
示例8: test
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Test
public void test(PhantomJSDriver driver) {
driver.get("https://bonigarcia.github.io/selenium-jupiter/");
assertThat(driver.getPageSource(), notNullValue());
}
示例9: setup
import org.openqa.selenium.phantomjs.PhantomJSDriver; //導入方法依賴的package包/類
@Before
public void setup() {
driver = new PhantomJSDriver();
driver.get("http://www.jan-exner.de/astro");
js = (JavascriptExecutor) driver;
}