Search in sources :

Example 31 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project cucumber-jvm by cucumber.

the class RentACarSupport method rentACar.

public void rentACar() {
    WebDriver driver = new HtmlUnitDriver();
    try {
        driver.get(BASE_URL + "rent");
        WebElement rentButton = driver.findElement(By.id("rentButton"));
        rentButton.click();
    } finally {
        driver.close();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 32 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project oxAuth by GluuFederation.

the class SelectAccountHttpTest method setUp.

@BeforeTest
public void setUp() {
    driver = new HtmlUnitDriver(true);
    pageConfig = newPageConfig(driver);
}
Also used : HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) BeforeTest(org.testng.annotations.BeforeTest)

Example 33 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project wechat by dllwh.

the class SinaWeiboCN method getSinaCookie.

/**
 * ----------------------------------------------- [私有方法]
 */
/**
 * @方法描述: 获取新浪微博的cookie,这个方法针对weibo.cn有效,对weibo.com无效
 *        weibo.cn以明文形式传输数据,请使用小号
 * @param username
 *            新浪微博用户名
 * @param password
 *            新浪微博密码
 * @return
 */
public static String getSinaCookie(String username, String password) throws Exception {
    HtmlUnitDriver driver = new HtmlUnitDriver();
    driver.setJavascriptEnabled(true);
    driver.get("http://login.weibo.cn/login/");
    /**
     * 手机号/电子邮箱/会员帐号:
     */
    WebElement mobile = driver.findElementByCssSelector("input[name=mobile]");
    mobile.sendKeys(new CharSequence[] { username });
    /**
     * 密码
     */
    WebElement pass = driver.findElementByCssSelector("input[name^=password]");
    pass.sendKeys(new CharSequence[] { password });
    /**
     * 图片验证码
     */
    WebElement ele = driver.findElementByCssSelector("img");
    String src = ele.getAttribute("src");
    String cookie = concatCookie(driver);
    HttpRequest request = new HttpRequest(src);
    request.setCookie(cookie);
    String imageCode = "";
    WebElement code = driver.findElementByCssSelector("input[name^=code]");
    code.sendKeys(new CharSequence[] { imageCode });
    /**
     * 记住登录状态,需支持并打开手机的cookie功能。
     */
    WebElement rem = driver.findElementByCssSelector("input[name=remember]");
    rem.click();
    /**
     * 登录按钮
     */
    WebElement submit = driver.findElementByCssSelector("input[name=submit]");
    submit.click();
    String result = concatCookie(driver);
    if (result.contains("gsid_CTandWM")) {
        return result;
    }
    throw new Exception("weibo login failed");
}
Also used : HttpRequest(cn.edu.hfut.dmic.webcollector.net.HttpRequest) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 34 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project saga by timurstrekalov.

the class InstrumentingProxyServerIT method setUp.

@Before
public void setUp() throws Exception {
    final InstanceFieldPerPropertyConfig config = new InstanceFieldPerPropertyConfig();
    proxyServer = new InstrumentingProxyServer(new HtmlUnitBasedScriptInstrumenter(config));
    fileServer = new FileServer(new File(getClass().getResource("/tests").toURI()).getAbsolutePath());
    proxyServerPort = proxyServer.start();
    fileServerPort = fileServer.start();
    final String proxyUrl = "localhost:" + proxyServerPort;
    final Proxy proxy = new Proxy().setProxyType(Proxy.ProxyType.MANUAL).setHttpProxy(proxyUrl).setSslProxy(proxyUrl);
    final DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
    desiredCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
    desiredCapabilities.setBrowserName(BrowserType.FIREFOX);
    driver = new HtmlUnitDriver(desiredCapabilities) {

        @Override
        protected WebClient newWebClient(final BrowserVersion version) {
            config.setBrowserVersion(version);
            return WebClientFactory.newInstance(config);
        }
    };
}
Also used : Proxy(org.openqa.selenium.Proxy) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) InstanceFieldPerPropertyConfig(com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig) InstrumentingProxyServer(com.github.timurstrekalov.saga.core.server.InstrumentingProxyServer) File(java.io.File) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) WebClient(com.gargoylesoftware.htmlunit.WebClient) FileServer(com.github.timurstrekalov.saga.core.FileServer) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Before(org.junit.Before)

Example 35 with HtmlUnitDriver

use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project oxAuth by GluuFederation.

the class BaseTest method initWebDriver.

protected WebDriver initWebDriver(boolean useNewDriver, boolean cleanupCookies) {
    // Allow to run test in multi thread mode
    HtmlUnitDriver currentDriver;
    if (useNewDriver) {
        currentDriver = new HtmlUnitDriver(true);
    } else {
        startSelenium();
        currentDriver = driver;
        if (cleanupCookies) {
            System.out.println("authenticateResourceOwnerAndGrantAccess: Cleaning cookies");
            deleteAllCookies();
        }
    }
    return currentDriver;
}
Also used : HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Aggregations

HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)39 WebDriver (org.openqa.selenium.WebDriver)12 WebElement (org.openqa.selenium.WebElement)10 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)9 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)9 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 Before (org.junit.Before)5 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)5 Test (org.junit.Test)4 SafariDriver (org.openqa.selenium.safari.SafariDriver)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 File (java.io.File)3 URL (java.net.URL)3 TimeoutException (org.openqa.selenium.TimeoutException)3 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)3 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3