0

Im running my selenium test on different browsers using selenium webdiver, but they all need interactive mode for runnung the tests, can we run these tests without interactive mode?

Abid Ali
  • 23
  • 6
  • What do you mean with `interactive` mode? – Andrei Suvorkov Jul 17 '18 at 10:46
  • For chrome and firefox, you can minimize the browser window during test running, but IE should not support that. – yong Jul 17 '18 at 11:50
  • I mean when the tests are running we need to make sure that brower on which the test is running should active, not in minimize mode and not running in background, i want to get rid of this. – Abid Ali Jul 17 '18 at 11:51
  • @yong i have run the tests using an agent on chrome but it as still the same issue – Abid Ali Jul 17 '18 at 11:53
  • Did your script do some things like mouse over on page? Generally, for click, sendkeys not require browser window is active ( obtain the focus). But mouse over only work on the active browser window. – yong Jul 17 '18 at 11:57
  • My script do everything like, button click, sendkeys, mouse over etc. Is there still any solution for it? – Abid Ali Jul 17 '18 at 12:11

1 Answers1

0

There are several solutions for this:

1. You could use headless testing method, try using HtmlUnitDriver, PhantomJSDriver,

2. use Docker with pre-set image, here is the example

Bellow are code examples for headless tests,(although in java, I see You're looking in c#), but it might help

HTMLdriver

@Test
public void runHtmlHeadless() {
    String URl = "https://www.google.com";
    HtmlUnitDriver driver = new HtmlUnitDriver();
    driver.setJavascriptEnabled(true);
    driver.get(URl);
    System.err.println("TITLE: " + driver.getTitle());
}

Chrome

  @Test
  public void createChromeDriverHeadless() throws IOException
  {

      System.setProperty("webdriver.chrome.driver", "/Users/user/Downloads/chromedriver");

      ChromeOptions chromeOptions = new ChromeOptions();
      chromeOptions.setBinary("//Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
      chromeOptions.addArguments("--headless");

      WebDriver driver = new ChromeDriver(chromeOptions);
      driver.navigate().to("https://the-internet.herokuapp.com/login");

      WebDriverWait waitForUsername = new WebDriverWait(driver, 5000);
      waitForUsername.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));

      driver.findElement(By.id("username")).sendKeys("tomsmith");
      driver.findElement(By.cssSelector("button.radius")).click();

      WebDriverWait waitForError = new WebDriverWait(driver, 5000);
      waitForError.until(ExpectedConditions.visibilityOfElementLocated(By.id("flash")));

      Assert.assertTrue(driver.findElement(By.id("flash")).getText().contains("Your password is invalid!"));
      driver.quit();
  }

Hope this helps,

Kovacic
  • 1,473
  • 6
  • 21