10

控制我正在使用Serenity BDD(Selenium)在Chrome中执行自动化测试。Chrome正在通过自动化测试软件

我不得不下载新的ChromeDriver,因为我的测试无法运行 - >测试会打开ChromeDriver,但无法“以用户身份浏览”。当我搜索这个问题时,他们说我必须更新ChromeDriver。

因此,我将ChromeDriver更新至版本2.28,并且我还将Chrome版本更新至版本57.0.2987.98。

但现在 - 每次我跑我的测试这恼人的短信来了:

的Chrome是由自动化测试软件

控制,它问我,如果我想保存密码。 (我不能添加照片,因为我没有足够的“点”)

在以前的版本中,我曾设法阻止这些两件事情:

public class CustomChromeDriver implements DriverSource { 

    @Override 
    public WebDriver newDriver() { 
     try { 
      DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
      Proxy proxy = new Proxy(); 
      String proxyServer = String.format("AProxyIDontWantToDisplay", System.getenv("proxy.username"), System.getenv("proxy.password")); 
      proxy.setHttpProxy(proxyServer); 
      capabilities.setCapability("proxy", proxy); 
      ChromeOptions options = new ChromeOptions(); 
      options.addArguments(Arrays.asList("--no-sandbox","--ignore-certificate-errors","--homepage=about:blank","--no-first-run")); 
      capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
      ChromeDriver driver = new ChromeDriver(capabilities); 
      return driver; 
     } catch (Exception e) { 
      throw new Error(e); 
     } 
    } 

    @Override 
    public boolean takesScreenshots() { 
     return true; 
    } 
} 

我知道有这一个(A link to same issue), 但有太多的答案不起作用。

任何人都知道如何删除?

+0

关于“自动控制”文本弹出:是否存在它引起的问题?我有一天在和Chrome驱动器搞混了,它没有显示屏幕截图等,也没有引起任何元素交互问题。 –

+0

不,不是真的,我有一些组件下弹出,不会显示在屏幕截图时,他们被点击。多数民众赞成为什么:) – BobbyB

+0

这是否能够导航网址和交互元素? – NarendraR

回答

5

关于“Chrome正在由自动测试软件控制”文本弹出:它不会影响您的测试。要处理其他事情(例如:保存密码),您可以在代码中添加以下行。

ChromeOptions options = new ChromeOptions(); 
Map<String, Object> prefs = new HashMap<String, Object>(); 
prefs.put("profile.default_content_settings.popups", 0); 
options.addArguments("disable-extensions"); 
prefs.put("credentials_enable_service", false); 
prefs.put("password_manager_enabled", false); 
options.setExperimentalOption("prefs", prefs); 
options.addArguments("chrome.switches","--disable-extensions"); 
options.addArguments("--test-type"); 
DesiredCapabilities cap = DesiredCapabilities.chrome(); 
cap.setCapability(ChromeOptions.CAPABILITY, options); 
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); 
System.setProperty("webdriver.chrome.driver",*path of chromedriver.exe*); 
wb = new ChromeDriver(cap); 

希望它能工作。

+1

此解决方案不会停止在Java中使用时显示的通知。 只有'options.addArguments(“disable-infobars”);'工作正常 –

+1

要禁用通知,请添加: options.addArguments(“ - disable-notifications”); –

19

一下添加到您传递给驾驶员的选项:

options.addArguments("disable-infobars"); 
0
Map<String, Object> prefs = new HashMap<String, Object>(); 
//To Turns off multiple download warning 
prefs.put("profile.default_content_settings.popups", 0); 

prefs.put("profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1); 

//Turns off download prompt 
prefs.put("download.prompt_for_download", false); 
        prefs.put("credentials_enable_service", false); 
//To Stop Save password propmts 
prefs.put("password_manager_enabled", false); 

ChromeOptions options = new ChromeOptions(); 
options.addArguments("chrome.switches","--disable-extensions"); 
//To Disable any browser notifications 
options.addArguments("--disable-notifications"); 
//To disable yellow strip info bar which prompts info messages 
options.addArguments("disable-infobars"); 

options.setExperimentalOption("prefs", prefs); 
System.setProperty("webdriver.chrome.driver", "Chromedriver path"); 
options.addArguments("--test-type"); 
driver = new ChromeDriver(options); 
Log.info("Chrome browser started"); 
3

五月有人需要这样的水豚,的Watir应该是这样的:

Capybara.register_driver :chrome do |app| 
    $driver = Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => [ "--disable-infobars" ]}) 
end 
0

如果有人使用Rails 5。1+,它改变了结构测试了一下,水豚在此文件中配置现在系统测试:

application_system_test_case.rb 

您可以添加“ARGS”在选项driven_by这样的:

driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { args: ["--disable-infobars"] } 
0

它通过使用addArguments(阵列( “禁用-信息栏”))

这是对我的作品的Facebook/PHP-webdriver的

$options = new ChromeOptions(); 
    $options->addArguments(array("disable-infobars")); 
    $capabilities = DesiredCapabilities::chrome(); 
    $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); 
    $this->driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities); 
1

虽然disable-infobars路线会工作,它可能会抑制在所有情况下(如建议here)信息栏,而不仅仅是在OP指的是这种情况。如果你没有得到一些重要的信息,这是最好的办法,如果将来会导致意想不到的和莫名其妙的行为。

我认为这是更好地利用所提供的enable-automation开关禁用它excludeSwitches区域你的配置/设置,而无所作为至于disable-inforbarsenable-automation交换机的描述:

告知用户他们的浏览器正在被自动测试控制。

对于nightwatch.conf.js它会是这个样子(和工作对我来说):

desiredCapabilities: { 
    ... 
    chromeOptions: { 
    excludeSwitches: ['enable-automation'], 
    ... 
    } 
} 

这应该只是做我们之后:摆脱特定讨厌的消息!

编辑[2017-11-14]:这现在导致更为恼人的Disable Developer Mode Extensions警报/警告。我试过每一个相关的标志/开关,我可以找到可能有帮助,但无济于事。我已经提交了一个Chromium的bug,所以我们会看到,如果我得到一个解决方案,我会尝试在这里摆动。

0

量角器解决方案:

我来到这里寻找一个量角器的解决方案,如果有用的人,我发现,从上面的回答可以帮助;用量角器可以Chrome添加特定选项的chromeOptions对象,内部的功能在protractor.config文件中的对象,例如使用上面讨论的使用禁用 - 信息栏选项如下:

capabilities: { 
    'browserName': 'chrome', 
    'chromeOptions': { 
    'args': ['disable-infobars'] 
    } 
}, 

要使用enable -automation上面也讨论过:

capabilities: { 
    'browserName': 'chrome', 
    'chromeOptions': { 
    'excludeSwitches': ['enable-automation'] 
    } 
} 

在我的情况下,首选disable-infobars。