BrowserStackLocal - 无法连接到日志文件
BrowserStackLocal - could not connect to log files
我正在尝试 运行 使用本地浏览器堆栈与本地主机交互来远程自动进行 selenium 测试。我收到以下错误:
Eror while executing BrowserStackLocal start {"state":"disconnected","pid":7512,"message":{"genre":"error","message":"Could not connect to Files!"}}
然后我指定一个日志文件,然后它说:
BrowserStackLocal start {"state":"disconnected","pid":18308,"message":{"genre":"error","message":"Could not connect to -logFile!"}}
它挂在这条线上没有进一步的进展:
browserStackLocal.start(localArgs);
我的代码如下:
var capability = GetBrowserStackCapabilities();
SetBrowserStackLocal(capability);
webDriver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("BrowserStackServer") + "/wd/hub/"), capability);
private static DesiredCapabilities GetBrowserStackCapabilities()
{
var profile = ConfigurationManager.AppSettings.Get("BrowserStackProfile");
NameValueCollection caps = ConfigurationManager.GetSection(string.Format("capabilities/{0}", profile)) as NameValueCollection;
var environment = ConfigurationManager.AppSettings.Get("BrowserStackEnvironment");
NameValueCollection settings = ConfigurationManager.GetSection(string.Format("environments/{0}", environment)) as NameValueCollection;
DesiredCapabilities capability = new DesiredCapabilities();
if (caps != null)
{
foreach (string key in caps.AllKeys)
{
capability.SetCapability(key, caps[key]);
}
}
if (settings != null)
{
foreach (string key in settings.AllKeys)
{
capability.SetCapability(key, settings[key]);
}
}
string username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME") ?? ConfigurationManager.AppSettings.Get("BrowserStackUser");
string accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY") ?? ConfigurationManager.AppSettings.Get("BrowserStackKey");
capability.SetCapability("browserstack.user", username);
capability.SetCapability("browserstack.key", accesskey);
return capability;
}
private static void SetBrowserStackLocal(DesiredCapabilities capability)
{
if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
{
var browserStackLocal = new Local();
string accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY") ?? ConfigurationManager.AppSettings.Get("BrowserStackKey");
List<KeyValuePair<string, string>> localArgs = new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key", accesskey),
new KeyValuePair<string, string>("logFile", "C:/Temp/logfile.txt"),
new KeyValuePair<string, string>("force", "true")
};
browserStackLocal.start(localArgs);
FeatureContext.Current.SetBrowserStackLocal(browserStackLocal);
}
}
我的配置如下:
<appSettings>
<add key="BrowserStackUser" value="<redacted>" />
<add key="BrowserStackKey" value="<redacted>/>
<add key="BrowserStackServer" value="hub-cloud.browserstack.com" />
<add key="BrowserStackProfile" value="single" />
<add key="BrowserStackEnvironment" value="ie11" />
</appSettings>
<capabilities>
<single>
<add key="browserstack.debug" value="true" />
<add key="browserstack.local" value="true" />
</single>
</capabilities>
<environments>
<ie11>
<add key="os" value="Windows" />
<add key="os_version" value="8.1" />
<add key="browser" value="IE" />
<add key="browser_version" value="11.0" />
<add key="resolution" value="1024x768" />
</ie11>
</environments>
如何避免浏览器堆栈本地挂起并使用本地服务器开始远程测试?
错误“无法连接到 -logFile!”是由于不正确的参数 "logFile"。正确的参数是“logfile”(全部小写)。您应该在此处查看 BrowserStack 的文档 - https://github.com/browserstack/browserstack-local-csharp#logfile。
这是 Browserstack 本地 C# 绑定的工作片段:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using BrowserStack;
using System.Collections.Generic;
using OpenQA.Selenium.Chrome;
using System.Threading;
namespace BrowserStackLocalSample
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver;
var browserStackLocal = new Local();
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("key", "<access_key>"),
new KeyValuePair<string, string>("logfile", "path_To_log/log.txt"),
//new KeyValuePair<string, string>("binarypath", "/Tools/local/BrowserStackLocal"),
new KeyValuePair<string, string>("force", "true"),
};
browserStackLocal.start(bsLocalArgs);
Thread.Sleep(15000);
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browser", "Chrome");
capability.SetCapability("browser_version", "62.0");
capability.SetCapability("os", "Windows");
capability.SetCapability("os_version", "7");
capability.SetCapability("resolution", "1024x768");
capability.SetCapability("browserstack.local", "true");
capability.SetCapability("browserstack.user", "<username>");
capability.SetCapability("browserstack.key", "<access_key>");
driver = new RemoteWebDriver(
new Uri("http://hub.browserstack.com/wd/hub/"), capability
);
driver.Navigate().GoToUrl("http://localhost:45691/check");
Console.WriteLine(driver.Title);
driver.Quit();
browserStackLocal.stop();
}
}
}
我正在尝试 运行 使用本地浏览器堆栈与本地主机交互来远程自动进行 selenium 测试。我收到以下错误:
Eror while executing BrowserStackLocal start {"state":"disconnected","pid":7512,"message":{"genre":"error","message":"Could not connect to Files!"}}
然后我指定一个日志文件,然后它说:
BrowserStackLocal start {"state":"disconnected","pid":18308,"message":{"genre":"error","message":"Could not connect to -logFile!"}}
它挂在这条线上没有进一步的进展:
browserStackLocal.start(localArgs);
我的代码如下:
var capability = GetBrowserStackCapabilities();
SetBrowserStackLocal(capability);
webDriver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("BrowserStackServer") + "/wd/hub/"), capability);
private static DesiredCapabilities GetBrowserStackCapabilities()
{
var profile = ConfigurationManager.AppSettings.Get("BrowserStackProfile");
NameValueCollection caps = ConfigurationManager.GetSection(string.Format("capabilities/{0}", profile)) as NameValueCollection;
var environment = ConfigurationManager.AppSettings.Get("BrowserStackEnvironment");
NameValueCollection settings = ConfigurationManager.GetSection(string.Format("environments/{0}", environment)) as NameValueCollection;
DesiredCapabilities capability = new DesiredCapabilities();
if (caps != null)
{
foreach (string key in caps.AllKeys)
{
capability.SetCapability(key, caps[key]);
}
}
if (settings != null)
{
foreach (string key in settings.AllKeys)
{
capability.SetCapability(key, settings[key]);
}
}
string username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME") ?? ConfigurationManager.AppSettings.Get("BrowserStackUser");
string accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY") ?? ConfigurationManager.AppSettings.Get("BrowserStackKey");
capability.SetCapability("browserstack.user", username);
capability.SetCapability("browserstack.key", accesskey);
return capability;
}
private static void SetBrowserStackLocal(DesiredCapabilities capability)
{
if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
{
var browserStackLocal = new Local();
string accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY") ?? ConfigurationManager.AppSettings.Get("BrowserStackKey");
List<KeyValuePair<string, string>> localArgs = new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key", accesskey),
new KeyValuePair<string, string>("logFile", "C:/Temp/logfile.txt"),
new KeyValuePair<string, string>("force", "true")
};
browserStackLocal.start(localArgs);
FeatureContext.Current.SetBrowserStackLocal(browserStackLocal);
}
}
我的配置如下:
<appSettings>
<add key="BrowserStackUser" value="<redacted>" />
<add key="BrowserStackKey" value="<redacted>/>
<add key="BrowserStackServer" value="hub-cloud.browserstack.com" />
<add key="BrowserStackProfile" value="single" />
<add key="BrowserStackEnvironment" value="ie11" />
</appSettings>
<capabilities>
<single>
<add key="browserstack.debug" value="true" />
<add key="browserstack.local" value="true" />
</single>
</capabilities>
<environments>
<ie11>
<add key="os" value="Windows" />
<add key="os_version" value="8.1" />
<add key="browser" value="IE" />
<add key="browser_version" value="11.0" />
<add key="resolution" value="1024x768" />
</ie11>
</environments>
如何避免浏览器堆栈本地挂起并使用本地服务器开始远程测试?
错误“无法连接到 -logFile!”是由于不正确的参数 "logFile"。正确的参数是“logfile”(全部小写)。您应该在此处查看 BrowserStack 的文档 - https://github.com/browserstack/browserstack-local-csharp#logfile。
这是 Browserstack 本地 C# 绑定的工作片段:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using BrowserStack;
using System.Collections.Generic;
using OpenQA.Selenium.Chrome;
using System.Threading;
namespace BrowserStackLocalSample
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver;
var browserStackLocal = new Local();
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("key", "<access_key>"),
new KeyValuePair<string, string>("logfile", "path_To_log/log.txt"),
//new KeyValuePair<string, string>("binarypath", "/Tools/local/BrowserStackLocal"),
new KeyValuePair<string, string>("force", "true"),
};
browserStackLocal.start(bsLocalArgs);
Thread.Sleep(15000);
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browser", "Chrome");
capability.SetCapability("browser_version", "62.0");
capability.SetCapability("os", "Windows");
capability.SetCapability("os_version", "7");
capability.SetCapability("resolution", "1024x768");
capability.SetCapability("browserstack.local", "true");
capability.SetCapability("browserstack.user", "<username>");
capability.SetCapability("browserstack.key", "<access_key>");
driver = new RemoteWebDriver(
new Uri("http://hub.browserstack.com/wd/hub/"), capability
);
driver.Navigate().GoToUrl("http://localhost:45691/check");
Console.WriteLine(driver.Title);
driver.Quit();
browserStackLocal.stop();
}
}
}