Java Code Examples for com.codeborne.selenide.WebDriverRunner#setWebDriver()

The following examples show how to use com.codeborne.selenide.WebDriverRunner#setWebDriver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JustTestLahConfiguration.java    From justtestlah with Apache License 2.0 6 votes vote down vote up
/** Set the correct {@link org.openqa.selenium.WebDriver}. */
public synchronized void initWebDriver() {
  // for web and local testing the Selenide default behavior is sufficient
  System.setProperty("browser", browser);
  // not thread-safe!
  Configuration.headless = headless;
  Platform platform = getPlatform();
  if (platform.equals(Platform.ANDROID)) {
    WebDriverRunner.setWebDriver(webDriverBuilder.getAndroidDriver());
  } else if (platform.equals(Platform.IOS)) {
    WebDriverRunner.setWebDriver(webDriverBuilder.getIOsDriver());
  } else if (platform.equals(Platform.WEB)) {
    if (cloudProvider.equals("browserstack")) {
      WebDriverRunner.setWebDriver(webDriverBuilder.getWebDriver());
      open(baseUrl);
    } else {
      open(baseUrl);
      WebDriverRunner.setWebDriver(webDriverBuilder.getWebDriver());
    }
  }
  WebDriver driver = WebDriverRunner.getWebDriver();
  if (driver instanceof TakesScreenshot) {
    ocr.setDriver(driver);
  }
}
 
Example 2
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSaveScreenshotsOnFail() {
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    WebDriverRunner.setWebDriver(wdMock);
    doReturn("hello".getBytes(StandardCharsets.UTF_8))
            .when(wdMock).getScreenshotAs(OutputType.BYTES);

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(true);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getAttachments())
            .hasSize(1);

    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    assertThat(results.getAttachments())
            .containsKey(attachment.getSource());

    final String attachmentContent = new String(
            results.getAttachments().get(attachment.getSource()),
            StandardCharsets.UTF_8
    );

    assertThat(attachmentContent)
            .isEqualTo("hello");
}
 
Example 3
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSavePageSourceOnFail() {
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    WebDriverRunner.setWebDriver(wdMock);
    doReturn("dummy-page-source")
            .when(wdMock).getPageSource();

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .screenshots(false)
                .savePageSource(true);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getAttachments())
            .hasSize(1);

    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    assertThat(results.getAttachments())
            .containsKey(attachment.getSource());

    final String attachmentContent = new String(
            results.getAttachments().get(attachment.getSource()),
            StandardCharsets.UTF_8
    );

    assertThat(attachmentContent)
            .isEqualTo("dummy-page-source");
}
 
Example 4
Source File: BaseTest.java    From vaadin-app-layout with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    Optional<String> version = WebDriverManager.chromedriver().getVersions().stream().max(String::compareTo);
    if (version.isPresent()) {
        WebDriverManager.chromedriver().version(version.get()).setup();
        driver = new ChromeDriver();
        WebDriverRunner.setWebDriver(driver);
    } else {
        throw new IllegalStateException("No Chromedriver found!");
    }
}
 
Example 5
Source File: ManageBrowserCookieStepsTest.java    From akita with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    dmbs = new ManageBrowserSteps();
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    wpis = new WebPageInteractionSteps();
    webDriver = mock(WebDriver.class);
    WebDriverRunner.setWebDriver(webDriver);
    when(webDriver.manage()).thenReturn(mock(WebDriver.Options.class));
}
 
Example 6
Source File: DownloadTestWithDockerAndProxy.java    From testcontainers with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    Configuration.proxyHost = "host.testcontainers.internal";
    Configuration.proxyPort = proxyPort;
    Configuration.proxyEnabled = true;
    Configuration.fileDownload = PROXY;

    proxyServer = new SelenideProxyServer(new StaticConfig(), null);
    proxyServer.start();

    RemoteWebDriver driver = chrome.getWebDriver();
    WebDriverRunner.setWebDriver(driver, proxyServer);
}
 
Example 7
Source File: AbstractTest.java    From selenium-grid-extensions with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    readGridHostPort();

    DesiredCapabilities desiredCapabilities = firefoxWithSikuli();
    URL url = new URL(String.format("http://%s:%d/wd/hub", host, port));

    RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities);
    WebDriverRunner.setWebDriver(remoteWebDriver);
}
 
Example 8
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSaveLogs() {
    final LogEntry logEntry = new LogEntry(Level.ALL, 10, "SIMPLE LOG");
    final LogEntries logEntries = new LogEntries(Collections.singletonList(logEntry));
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    final Logs logsMock = mock(Logs.class);
    final Options optionsMock = mock(Options.class);

    WebDriverRunner.setWebDriver(wdMock);

    doReturn(optionsMock).when(wdMock).manage();
    doReturn(logsMock).when(optionsMock).logs();
    doReturn(logEntries).when(logsMock).get(LogType.BROWSER.toString());

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .enableLogs(LogType.BROWSER, Level.ALL)
                .savePageSource(false)
                .screenshots(false);

        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);

        final SelenideLog log = SelenideLogger.beginStep(
            "dummy source",
            "dummyMethod()",
            "param1",
            "param2");

        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    final String attachmentContent = new String(
        results.getAttachments().get(attachment.getSource()),
        StandardCharsets.UTF_8
    );

    assertThat(selenideStep.getAttachments()).hasSize(1);
    assertThat(results.getAttachments()).containsKey(attachment.getSource());
    assertThat(attachmentContent).isEqualTo(logEntry.toString());
}
 
Example 9
Source File: DockerChromeJupiterWithNestedTest.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void openSite(@DockerBrowser(type = CHROME) RemoteWebDriver driver) {
  WebDriverRunner.setWebDriver(driver);
  Selenide.open("https://bonigarcia.github.io/selenium-jupiter/");
}
 
Example 10
Source File: GoogleTestWithDockerTestNG.java    From testcontainers with MIT License 4 votes vote down vote up
@BeforeClass
public void startContainer() {
  chrome.start();
  WebDriverRunner.setWebDriver(chrome.getWebDriver());
}
 
Example 11
Source File: GoogleTestWithDocker.java    From testcontainers with MIT License 4 votes vote down vote up
@Before
public void setUp() {
  RemoteWebDriver driver = chrome.getWebDriver();
  WebDriverRunner.setWebDriver(driver);
}
 
Example 12
Source File: GoogleTestWithDockerNoVideo.java    From testcontainers with MIT License 4 votes vote down vote up
@Before
public void setUp() {
  RemoteWebDriver driver = chrome.getWebDriver();
  WebDriverRunner.setWebDriver(driver);
}
 
Example 13
Source File: GoogleTestWithFirefox.java    From testcontainers with MIT License 4 votes vote down vote up
@Before
public void setUp() {
  RemoteWebDriver driver = browser.getWebDriver();
  System.out.println(browser.getVncAddress());
  WebDriverRunner.setWebDriver(driver);
}