Remove infobar from Chrome when running tests with automated software

Asked

Viewed 2,083 times

0

I tried to implement the Chrome Options in my script to delete that yellow bar of Chrome information, which is displayed every time we are running automated tests ("Chrome is being Controlled by Automated test software"), but the result I had was the display of two Chrome windows: one minimized, displaying the infobar, and the other maximized without the infobar view, where my script was executed.

Please, would you know where I am going wrong? I have made several modifications but I could not fix this double browser opening:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace navegador.PageObjects
{
    public class acessaSite
    {
    public IWebDriver driver;
        public acessaSite(IWebDriver driver)
        {
        this.driver = driver;
        }
        public void acessaURL()
        {

         var options = new ChromeOptions();
         options.AddArguments("--disable-infobars");
         options.AddUserProfilePreference("credentials_enable_service", false);
         options.AddUserProfilePreference("profile.password_manager_enabled", false);
         driver = new ChromeDriver(options);

        driver.Manage().Window.Maximize();
        driver.Navigate().GoToUrl("https://meusite.com.br");
        Thread.Sleep(1000);
        }
    }
}

Grateful!

2 answers

1


Question solved! The final code was left:

[TestFixture]
public class Login
{
IWebDriver driver = null;
public capturaImagem tiraScreenshot;
public acessaSite navegador;
public LoginPositivo testePositivo;
public LoginNegativo testeNegativo;
public sair sessao;

    public Login()
    {
    ChromeOptions options = new ChromeOptions();
    options.AddArguments("--disable-infobars");
    options.AddArguments("start-maximized");
    driver = new ChromeDriver(options);

    tiraScreenshot = new capturaImagem(driver);
    navegador = new acessaSite(driver);
    testePositivo = new LoginPositivo(driver);
    testeNegativo = new LoginNegativo(driver);
    sessao = new sair(driver);
    }

    [TearDown]
    public void DepoisDosTestes()
    {
    driver.Close();
    }

    [Test]
    public void AutomacaoLogin()
    {
    navegador.acessaURL();
    testePositivo.UsuarioSenhaValidos();
    sessao.FazLogoff();
    testeNegativo.CamposEmBranco();
    testeNegativo.UsuarioInvalido();
    testeNegativo.SenhaInvalida();
    }
}

public class acessaSite
{
public IWebDriver driver;
public capturaImagem tiraScreenshot;

    public acessaSite(IWebDriver driver)
    {
    tiraScreenshot = new capturaImagem(driver);
    this.driver = driver;
    }

    public void acessaURL()
    {
    driver.Navigate().GoToUrl("https://www.meusite.com.br");
    Thread.Sleep(1000);
    tiraScreenshot.salvaImagem();
    Thread.Sleep(200);
    }

0

Hi, try instantiating Chrome options as follows:

            ChromeOptions options = new ChromeOptions();
            options.AddArguments("--disable-infobars");
            driver = new ChromeDriver(options);

This is a case where you should use the variable type explicitly, to pass the correct intention to the variable driver.

I’m putting this part to better illustrate what I answered below, try to see if it works that way:

    var options = new ChromeOptions();
    options.AddArguments("--disable-infobars");
    options.AddArguments("start-maximized"); //Isso deve iniciar o chrome maximizado
    options.AddUserProfilePreference("credentials_enable_service", false);
    options.AddUserProfilePreference("profile.password_manager_enabled", false);
    driver = new ChromeDriver(options);

    //driver.Manage().Window.Maximize();
    driver.Navigate().GoToUrl("https://meusite.com.br");
    Thread.Sleep(1000);
  • Hi Bruno, thanks for the tip, but even using explicitly not yet worked... just the fact of instantiating Chromeoptions, the code is already lost: ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);

  • Debugging realized that the second window is being opened when running driver.Manage().Window.Maximize();

  • Hi Carol, I couldn’t reproduce this scenario here, but what you do is change the maximize command by the following argument options.AddArguments("start-maximized");

  • Bruno, even changing this excerpt, the script gets lost and opens the other window when calling the driver: driver.Navigate().GoToUrl("https://www.meusite.com.br");. Is there any argument or something to access URL? I searched the internet but could not find.

  • @Carolciola, not just seen, but the constructor you created called "accessSite" also calls the driver, so I guess when the driver is called he ends up opening two browsers.

  • Bruno, I was able to solve the question. This class has a constructor because it is called by a main class. So the correct thing would be to increment the main class script with Chromeoptions, not this example class. The main class instantiated the driver, and when calling this example class, the driver coming from the main one was "thrown away" and another without any properties was opened.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.