[英]Handling browser pop-ups that stop processing in Java/Selenium
Environment : Selenium testing in Java against Chrome 环境 :针对Chrome的Java硒测试
Scenario : in the GUI of my application I have a button that causes a form full of data to be submitted to an external service, whereupon the user is re-directed to the external service landing page. 场景 :在我的应用程序的GUI中,我有一个按钮,该按钮使充满数据的表单提交到外部服务,随后用户被重定向到外部服务登录页面。
Because my application is inside my corporate firewall, a username/password has to be supplied for consumption by the external service, but the application is not aware of this, so doesn't provide it (it would work normally in production, but the test environment is a special case). 由于我的应用程序位于公司防火墙内部,因此必须提供用户名/密码以供外部服务使用,但该应用程序不知道这一点,因此不提供它(它可以在生产环境中正常工作,但需要经过测试环境是一种特殊情况)。 Therefore, a pop-up appears, and during manual testing the tester supplies a username and password manually and then submits the dialog. 因此,会出现一个弹出窗口,并且在手动测试期间,测试人员手动提供用户名和密码,然后提交对话框。 This is not a JavaScript dialog - I assume it's an actual modal Windows dialog, so it effectively halts processing and selenium just waits around till it's gone. 这不是JavaScript对话框-我认为它是一个实际的模态Windows对话框,因此它有效地暂停了处理,硒只是在等待直到消失。
Problem : I am trying to automate this process, and cannot get passed the dialog. 问题 :我正在尝试使此过程自动化,并且无法通过对话框。 Because the dialog prevents java/selenium from processing, I cannot implement code to handle the dialog, such as integrating AutoIt or using Robot , because program flow never gets to that code after the button is pressed. 因为对话框阻止Java / Selenium的处理,所以我无法实现处理对话框的代码,例如集成AutoIt或使用Robot,因为按下按钮后程序流就永远无法到达该代码。 Usually, I'd install an independent version of AutoIt to run on my machine in the background and catch the pop-up (not ideal, but it works), but due to very tight restrictions in the corporate domain policy this isn't possible in the short-term. 通常,我会安装一个独立版本的AutoIt在后台在我的计算机上运行并捕获弹出窗口(不理想,但可以运行),但是由于公司域策略的严格限制,这是不可能的在短期内。 I suspect they have a white-list for executables, so it may be tricky getting any third-party tool to work. 我怀疑他们有可执行文件的白名单,因此让任何第三方工具正常工作可能很棘手。
Can anybody think of a way around this? 有人可以考虑解决这个问题的方法吗?
I suspect it's not possible, but worth checking if any bright spark has any ideas. 我怀疑这是不可能的,但值得检查是否有任何火花有任何想法。
It's not supported in WebDriver so it can't be done using plain Selenium. WebDriver不支持此功能,因此无法使用普通的Selenium完成。
There is an issue open in the WebDriver project to support handling basic auth prompts: WebDriver项目中存在一个开放的问题,以支持处理基本身份验证提示:
https://github.com/w3c/webdriver/issues/385 https://github.com/w3c/webdriver/issues/385
https://github.com/SeleniumHQ/selenium/issues/453 https://github.com/SeleniumHQ/selenium/issues/453
Alas, the issue is open and nothing is implemented yet. las,这个问题尚未解决。
If you can't use AutoIt from another process because that process has to be in a certain whitelist, then you can probably use it from another thread using autoitx4java . 如果您不能从另一个进程使用AutoIt,因为该进程必须位于某个白名单中,那么您可以使用autoitx4java从另一个线程使用它 。 If you can detect the dialog itself then you should certainly do it, but AFAIK the dialogs of Chrome are transparent to AutoIt (any other technologies based on Windows UIAutomation). 如果您可以检测到对话框本身,那么您当然应该这样做,但是AFAIK Chrome的对话框对AutoIt(基于Windows UIAutomation的其他任何技术)都是透明的。 In this case, just spawn the thread before pressing the button, make this thread sleep for 1 second or so (in the first statement of the thread method), and then "blindly" type the user name, Tab key, the password, and Enter. 在这种情况下,只需在按下按钮之前生成线程,使该线程休眠1秒钟左右(在thread方法的第一条语句中),然后“盲目”键入用户名,Tab键,密码和输入。 It's not very element, but I believe it should work. 它不是非常重要的元素,但我认为它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.