コード例 #1
0
 private void waitForHandshake() throws WebDriverException {
   try {
     waitState.waitForHandshake(OperaIntervals.HANDSHAKE_TIMEOUT.getValue());
   } catch (WebDriverException e) {
     shutdown();
     throw e;
   }
 }
コード例 #2
0
 @Before
 public void setup() throws IOException {
   OperaIntervals.HANDSHAKE_TIMEOUT.setValue(new Duration(2, TimeUnit.SECONDS));
   profileDirectory = new TemporaryFolder().newFolder();
   capabilities.setCapability(PROFILE.getCapability(), profileDirectory.getPath());
 }
コード例 #3
0
 @After
 public void reset() {
   OperaIntervals.HANDSHAKE_TIMEOUT.setValue(DEFAULT_HANDSHAKE_TIMEOUT);
   environment.unset(OperaBinary.OPERA_PATH_ENV_VAR);
 }
コード例 #4
0
@NoDriver
@Ignore(products = {CORE, MINI, MOBILE, SDK})
public class OperaDesktopDriverTest extends OperaDesktopDriverTestCase {

  public static final Duration DEFAULT_HANDSHAKE_TIMEOUT =
      OperaIntervals.HANDSHAKE_TIMEOUT.getValue();

  public TestOperaDesktopDriver driver;
  public DesiredCapabilities capabilities = DesiredCapabilities.opera();
  public File profileDirectory;

  @Before
  public void setup() throws IOException {
    OperaIntervals.HANDSHAKE_TIMEOUT.setValue(new Duration(2, TimeUnit.SECONDS));
    profileDirectory = new TemporaryFolder().newFolder();
    capabilities.setCapability(PROFILE.getCapability(), profileDirectory.getPath());
  }

  @After
  public void tearDownDriver() {
    if (driver != null && driver.isRunning()) {
      driver.quit();
    }
  }

  @After
  public void reset() {
    OperaIntervals.HANDSHAKE_TIMEOUT.setValue(DEFAULT_HANDSHAKE_TIMEOUT);
    environment.unset(OperaBinary.OPERA_PATH_ENV_VAR);
  }

  @Test
  public void specificProfile() throws IOException {
    driver = new TestOperaDesktopDriver(capabilities);

    assertTrue(driver.isRunning());
    assertEquals(
        profileDirectory.getCanonicalPath(),
        driver.getSettings().profile().getDirectory().getCanonicalPath());
  }

  @Test
  public void startAndQuitOperaFourTimes() {
    for (int i = 0; i < 5; i++) {
      driver = new TestOperaDesktopDriver();
      assertTrue("Opera should be running", driver.isRunning());

      // TODO: What does this do?  Why is it here?
      driver.resetOperaPrefs("");
      assertTrue("Opera should be running", driver.isRunning());

      driver.quit();
    }
  }

  @Test
  public void autostartDisabled() {
    OperaSettings settings = new OperaSettings();
    settings.autostart(false);

    try {
      new TestOperaDesktopDriver(settings);
      fail("Expected exception");
    } catch (WebDriverException e) {
      assertThat(e.getCause(), instanceOf(ResponseNotReceivedException.class));
      assertThat(e.getMessage(), containsString("No response in a timely fashion"));
    }
  }

  @Test
  public void environmentalBinaryPathIsRespected() {
    environment.set(OperaBinary.OPERA_PATH_ENV_VAR, resources.executableBinary().getPath());

    try {
      new TestOperaDesktopDriver();
      fail("Expected exception");
    } catch (WebDriverException e) {
      assertThat(e.getCause(), instanceOf(OperaRunnerException.class));
      assertThat(e.getMessage(), containsString("Could not start Opera"));
    }
  }

  /**
   * This test is known to fail if OPERA_PATH points to a shell script or a symlink, as is the case
   * on Debian.
   */
  @Test
  @Ignore(platforms = LINUX)
  public void environmentalBinaryPathWorks() throws IOException {
    File binary = new OperaBinary(OperaProduct.DESKTOP).getFile();
    environment.set(OperaBinary.OPERA_PATH_ENV_VAR, binary.getPath());

    driver = new TestOperaDesktopDriver();
    assertEquals(binary.getCanonicalPath(), driver.getSettings().getBinary().getCanonicalPath());
    assertEquals(binary.getCanonicalPath(), new File(driver.getOperaPath()).getCanonicalPath());
    assertEquals(binary.getCanonicalPath(), driver.utils().getBinaryPath());
  }

  @Test
  public void capabilitiesForDesktopAreCorrect() {
    capabilities.setCapability(NO_QUIT.getCapability(), true);

    driver = new TestOperaDesktopDriver(capabilities);

    Capabilities actual = driver.getSettings().toCapabilities();
    assertEquals(actual.getCapability(AUTOSTART.getCapability()), true);
    assertEquals(actual.getCapability(PRODUCT.getCapability()), OperaProduct.DESKTOP);
    assertEquals(actual.getCapability(NO_QUIT.getCapability()), true);
    assertEquals(actual.getCapability(NO_RESTART.getCapability()), false);
  }

  @Test
  @NeedsLocalEnvironment
  public void browserDoesNotQuit() {
    OperaSettings settings = new OperaSettings();
    settings.setDetach(true);

    driver = new TestOperaDesktopDriver(settings);
    int processID = driver.utils().getPID();
    driver.quit();

    // Driver should be shut down, and there should be no connection to browser
    assertFalse(driver.getServices().isConnected());

    // But browser should be running
    assertTrue(ProcessManager.isPidRunning(processID));

    ProcessManager.killPID(processID);
  }
}