本文介绍了Selenium Browserstack 会话中的问题:加载现有的 Chrome 配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Browserstack Automate 上使用 Selenium (Python) 远程运行测试.

I am running a test with Selenium (Python) remotely on Browserstack Automate.

目标:我想在 Browserstack 上开始一个会话,并登录现有的 Chrome 配置文件.

Goal: I want to start a session on Browserstack, with an existing Chrome profile logged in.

  • -- 基本目标:我正在尝试访问 Whatsapp Web,而不必每次都扫描 QR 码.(构建自动化的 Whatsapp 服务)

所以第一次创建一个新的个人资料是可以的 - 扫描二维码一次,然后重新使用该个人资料.

So it would be ok to have a new profile made the first time - scan the QR code once and then re-use that profile afterwards.

方法:我尝试使用 Chrome 选项,并为 user-data-dir 指定一个参数.这受到了其他几个 StackOverflow 答案的启发.

Method: I try to use Chrome Options, and specify an argument for user-data-dir. This was inspired by several other StackOverflow answers.

代码:

desired_caps = {
    'browser': 'Chrome',
    'browser_version': '69.0 beta',
    'os': 'Windows',
    'os_version': '10',
    'resolution': '1024x768',
    'browserstack.debug': 'true',
}
desired_caps['browserstack.local'] = True
desired_caps['chromeOptions'] = {}
desired_caps['chromeOptions']['args'] = [r'--user-data-dir=C:\Users\gille\AppData\Local\Google\Chrome\User Data']
driver = webdriver.Remote(command_executor='http://MYBROWSERSTACKHUB', desired_capabilities=desired_caps)

我正在尝试在 Browserstack(本地)上运行它,但在运行时出现以下错误:

I am trying to run this on Browserstack (locally), but I am getting the following error when running:

无法初始化类 org.openqa.selenium.os.Kernel32"

"Could not initialize class org.openqa.selenium.os.Kernel32"

查看浏览器堆栈错误的图片

我尝试指定一个尚不存在的新随机配置文件,例如:

I have tried specifying a new random profile that did not exist yet, e.g.:

desired_caps['chromeOptions']['args'] = [r'--user-data-dir=C:\Users\gille\AppData\Local\Google\Chrome\User Data\ProfileXXX']

但同样的错误弹出.

(我也尝试过其他对我不起作用的方法:- 保存和重新加载 cookie- 更改 session_id 和 session_url(不适用于 Browserstack)

(I have also tried other methods that did not work for me: - Saving and re-loading cookies - Changing the session_id and session_url (does not work on Browserstack) )

我觉得:- 或者这可能是 Browserstack 的问题,- 或者我包含了错误的 user-data-dir 路径,应该使用不同的路径,例如chrome_options.add_argument("user-data-dir=" + os.path.dirname(sys.argv[0])

I feel that: - or this could be a problem with Browserstack, - or I am including the wrong path for user-data-dir, and should go with a different, e.g. chrome_options.add_argument("user-data-dir=" + os.path.dirname(sys.argv[0])

但我不熟悉最后一个 - 所以我不确定下一步要做什么.您有什么建议吗?

But I am unfamiliar with the last one - So I am unsure what the next step to take is.Do you have any advice?

推荐答案

使用大写如下:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL(CloudConfiguration.URL), caps);

这篇关于Selenium Browserstack 会话中的问题:加载现有的 Chrome 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:38