You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SelenideConfig.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.qa.util;
  21. import com.codeborne.selenide.Configuration;
  22. import com.codeborne.selenide.WebDriverRunner;
  23. import com.sonar.orchestrator.Orchestrator;
  24. import java.util.Locale;
  25. import java.util.stream.Collectors;
  26. import org.openqa.selenium.WebDriver;
  27. import static java.util.Arrays.stream;
  28. public class SelenideConfig {
  29. private enum Browser {
  30. FIREFOX("(v46 and lower)"),
  31. MARIONETTE("(recent Firefox, require Geckodriver)"),
  32. CHROME("(require Chromedriver)");
  33. private final String label;
  34. Browser(String label) {
  35. this.label = label;
  36. }
  37. static Browser of(String s) {
  38. try {
  39. return Browser.valueOf(s.toUpperCase(Locale.US));
  40. } catch (Exception e) {
  41. throw new IllegalArgumentException("Invalid browser: " + s + ". Supported values are " +
  42. stream(values()).map(b -> b.name() + " " + b.label).collect(Collectors.joining(", ")));
  43. }
  44. }
  45. }
  46. public static WebDriver configure(Orchestrator orchestrator) {
  47. String browserKey = orchestrator.getConfiguration().getString("orchestrator.browser", Browser.FIREFOX.name());
  48. Browser browser = Browser.of(browserKey);
  49. Configuration.browser = browser.name();
  50. Configuration.baseUrl = orchestrator.getServer().getUrl();
  51. Configuration.timeout = 8_000;
  52. Configuration.reportsFolder = "build/screenshots";
  53. Configuration.screenshots = true;
  54. Configuration.captureJavascriptErrors = true;
  55. Configuration.savePageSource = true;
  56. Configuration.browserSize = "1280x1024";
  57. return getWebDriver();
  58. }
  59. static WebDriver getWebDriver() {
  60. return WebDriverRunner.getWebDriver();
  61. }
  62. }