【问题标题】:How to handle windows authentication popup in Robot Framework RIDE?如何在 Robot Framework RIDE 中处理 Windows 身份验证弹出窗口?
【发布时间】:2017-04-23 10:51:48
【问题描述】:

我的应用程序的 Windows 身份验证弹出窗口与此应用程序 https://www.engprod-charter.net/ 类似,我使用下面的代码使用 python 处理 selenium 中的窗口身份验证弹出窗口。

from selenium import webdriver
import time
import win32com.client

driver=webdriver.Firefox()
driver.maximize_window()
driver.get('https://www.engprod-charter.net/')
shell = win32com.client.Dispatch("WScript.Shell")   
shell.Sendkeys("username")  
shell.Sendkeys("{TAB}")
shell.Sendkeys("password@123") 
time.sleep(5)
shell.Sendkeys("{ENTER}")
time.sleep(2)
driver.quit()

但由于我将 python 2.7.12 用于 Robot Framework,因此那里似乎不支持 win32com.client。我想知道我必须在 Robot Framework 中使用什么库来处理这种情况。

我不是在问完整的解决方案,因为这不是 stackoverflow 中的正确方法,只是想提示我应该尝试什么来处理我的场景。谢谢

【问题讨论】:

    标签: python selenium robotframework


    【解决方案1】:

    您可以使用处理窗口输入和类似内容的AutoItLibrary 来实现您的场景。基本上控制整个 GUI 而不仅仅是浏览器。

    首先安装 AutoItLibrary for Robot Framework

    1. 确保你已经安装了 32 位的 python(比如 python 2.7.6)
    2. here安装pywin32-217.win32-py2.7.exe for 32 bit
    3. 下载AutoItLibrary并解压文件夹
    4. 以管理员身份打开命令提示符并转到下载的 AautoItLibrary 文件夹文件夹(cd...\AutoItLibrary-1.1.post1),然后编写此命令并按 Enter python setup.py install

    现在在 Robot Framework 中包含 AutoItLibrary 让我们知道这是否有效,我很想知道

    【讨论】:

    • 你找到什么了吗@ShoaibAkhtar? :)
    • 还没有成功。我已经将 AutoIt 与 Java 一起使用,但仍然无法在 Robot Framework 中使用 AutoIt,因为我是 Robot Framework 的新手
    • 是的,唯一一致的解决方法是将 AutoItLibrary 与自定义 firefox 配置文件一起使用。 1. First create your own firefox profile (google how to create). 2. Then launch firefox with the new profile created, and launch the <url> you want to test. 3. When the authorization alert come out, manually input the username & password and click enter or proceed. This will save the username & password to this browser cache/cookie.. 4. Next, on RIDE -> Open Browser <url> firefox ff_profile_dir=${your_new_profile_dir} Sleep 2s AutoItLibrary.Send {ENTER}
    【解决方案2】:

    这可以使用java中的Robot Class轻松完成,可以在需要时在Robotframework测试中运行。

    即一个 .jar 将作为 windows 身份验证的处理程序弹出。

    在 RobotFramework 中,您只需要运行一个 .jar 来处理您的弹出窗口。

    如果你不习惯 Java,我可以帮你提供一个示例代码。

    【讨论】:

    • 我知道 Java 中的 Robot 类。但目前我正在研究 Robot Framework 和 python,所以想知道如何在那里处理 windows 身份验证
    • 在 python 中似乎没有更简单的方法!那么为什么不使用 Java 中的简单方法并使其可从 RobotFramework 或 Python(基本上从命令行)调用。这是你的选择!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多