Search in sources :

Example 76 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project webpieces by deanhiller.

the class Selenium2Example method main.

public static void main(String[] args) {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new FirefoxDriver();
    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");
    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));
    // Enter something to search for
    element.sendKeys("Cheese!");
    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();
    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {

        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });
    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());
    //Close the browser
    driver.quit();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 77 with FirefoxDriver

use of org.openqa.selenium.firefox.FirefoxDriver in project iTest by e-government-ua.

the class SetupAndTeardown method SetUp.

@BeforeMethod(alwaysRun = true)
public void SetUp() throws IOException {
    //        driver = new FirefoxDriver(profileFF);
    if (null == driver) {
        /**
             * ******* Для локального тестирования установить switch ("chrome")
             * для jenkins switch ("firefox") **********
             */
        switch("firefox") {
            case "firefox":
                /**
                     * ******* Закоментить для для запуска на своем профиле и
                     * откоментить для запуска на дефолтном **********
                     */
                //Save the path of the XPI files as per your saved location
                String cryptopluginPath = "src/test/resources/files/cryptoplugin_ext_id@privatbank.ua.xpi";
                File cryptoplugin = new File(cryptopluginPath);
                FirefoxProfile profile = new FirefoxProfile();
                //                    profile.addExtension(cryptoplugin);
                profile.setEnableNativeEvents(true);
                profile.setAcceptUntrustedCertificates(true);
                //                    profile.addExtension(cryptoplugin);
                /**
                     * ******* Раскомментить для запуска на своем профиле и
                     * закоментить для дефолтного **********
                     */
                //   ProfilesIni allProfiles = new ProfilesIni();
                //   FirefoxProfile profile = allProfiles.getProfile("default");
                profile.setPreference("extensions.cryptoplugin_ext_id@privatbank.currentVersion", "9.9.9");
                profile.setEnableNativeEvents(true);
                profile.setAcceptUntrustedCertificates(true);
                profile.setAssumeUntrustedCertificateIssuer(true);
                profile.setPreference("javascript.enabled", true);
                profile.setPreference("geo.enabled", false);
                profile.setPreference("extensions.cryptoplugin_ext_id@privatbank.ua.currentVersion", "999.999.999");
                capabilities = DesiredCapabilities.firefox();
                capabilities.setCapability(FirefoxDriver.PROFILE, profile);
                capabilities.setCapability("unexpectedAlertBehaviour", "ignore");
                System.out.println("Tests will be run (or rerun) in Firefox with custom profile...");
                driver = WebDriverFactory.getDriver(capabilities);
                /**
                     * ******* Для локального тестирования **********
                     */
                //                  case "chrome":
                //                    System.setProperty("webdriver.chrome.driver", "src\\test\\resources\\files\\chromedriver.exe");
                //                  capabilities = DesiredCapabilities.chrome();
                //                options = new ChromeOptions();
                //              System.out.println("Tests will be run (or rerun) in Chrome with custom profile...");
                //            break;
                //      default:
                this.driver = new FirefoxDriver();
                System.out.println("Tests will be run (or rerun) in Firefox...");
                break;
        }
        driver = WebDriverFactory.getDriver(capabilities);
        this.driver.manage().timeouts().implicitlyWait(CV.implicitTimeWait, TimeUnit.SECONDS);
        this.driver.manage().window().maximize();
        this.driver.manage().deleteAllCookies();
    }
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File)

Aggregations

FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)77 WebDriver (org.openqa.selenium.WebDriver)59 WebElement (org.openqa.selenium.WebElement)46 Actions (org.openqa.selenium.interactions.Actions)18 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)9 File (java.io.File)8 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)4 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)4 URL (java.net.URL)3 Before (org.junit.Before)3 Test (org.junit.Test)3 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 BeforeClass (org.junit.BeforeClass)2 Cookie (org.openqa.selenium.Cookie)2