简体   繁体   English

您如何确定是否在Python中打开了“打开”窗口资源管理器窗口?

[英]How do you determine if an “Open” windows explorer window is open in Python?

In Python I'm using Selenium Chromedriver (both of which I'm fairly new to) to learn how to do some very basic automation. 在Python中,我正在使用Selenium Chromedriver(我对这两者都很陌生)来学习如何进行一些非常基本的自动化。 The test that I'm doing at the moment is to determine that the user would be able to open a file using Ctrl/Cmd + O to open the file browser. 我目前正在执行的测试是确定用户是否可以使用Ctrl / Cmd + O打开文件以打开文件浏览器。 This part works like a charm. 这部分的工作原理很像魅力。 However, in order to determine whether the test passes or fails I need the program to know that the file explorer opens. 但是,为了确定测试是通过还是失败,我需要程序知道文件浏览器已打开。 Does anyone know of a good way to do this? 有人知道这样做的好方法吗? Thank you! 谢谢!

All I have for the current test at the moment is: 目前,我目前进行的测试只有:

def test_open_file(self):
   ActionChains(self.driver).key_down(Keys.CONTROL).send_keys("o").perform()

Selenium doesn't have access to any of the browser chrome and thus cannot tell you whether the file explorer is open or not. Selenium无法访问任何浏览器镶边,因此无法告诉您文件浏览器是否打开。 (Selenium uses the WebDriver specification which only deals with the content of web pages.) (Selenium使用WebDriver规范,该规范仅处理网页的内容。)


While you might be able to figure something out using an OS-specific tool, I would actually recommend that you not test the presence of the actual file explorer. 尽管您可以使用特定于操作系统的工具来弄清某些东西,但实际上我建议您不要测试实际文件浏览器的存在。

One, assuming you're testing a web application, the file explorer itself lives outside of the scope of your application, and thus there's little value in testing that far. 一个,假设您正在测试Web应用程序,文件浏览器本身就不在您的应用程序范围内,因此到目前为止进行测试没有什么价值。 You really only need to test up to the boundary between your application and the browser, ie, the JavaScript API provided by the browser that triggers the opening of the file explorer—in this case, a keyboard shortcut. 您实际上只需要测试应用程序和浏览器之间的边界即可,即浏览器提供的触发文件浏览器打开的JavaScript API(在本例中为键盘快捷键)。

Two, Selenium is a fairly expensive tool, not just because it runs an entire browser but because it inevitably requires integrating the majority of your system. 第二,Selenium是一个相当昂贵的工具,不仅因为它运行整个浏览器,而且因为它不可避免地需要集成大多数系统。 For such a granular detail of your application, this could be more cheaply tested with, say, a JavaScript unit test. 对于您的应用程序如此细致的细节,可以使用JavaScript单元测试来进行更便宜的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM