![](/img/trans.png)
[英]Unable to run silverlight application in private browser mode (incognito window)
[英]LeanFT Opening Browser in Incognito Mode
问题:遗憾的是,C#中的LeanFT无法以隐身模式打开浏览器。 我无法在路径中添加-incognito,因为我没有管理员权限。 我能做什么? 我在想Sendkeys(“^ + N”); 但不知道如何通过键盘做到这一点,或者它是否可以工作,因为浏览器已经实例化。
有没有其他人遇到这个问题? 由于LeanFT不允许隐身模式自动运行,因此我说的非常麻烦。
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.Verifications;
using System.Diagnostics;
using System.Threading;
using HP.LFT.SDK.Web;
using HP.LFT.Report;
using System.Drawing;
namespace Xpathtest
{
[TestClass]
public class LeanFtTest : UnitTestClassBase<LeanFtTest>
{
//The Browser object on which the test will be run
IBrowser browser;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
GlobalSetup(context);
}
[TestInitialize]
public void TestInitialize()
{
browser = BrowserFactory.Launch(BrowserType.Chrome);
}
[TestMethod]
public void TestMethod1()
{
try
{
// Navigate to Rally
browser.Navigate("-incognito https://rally1.rallydev.com/");
browser.Sync();
Thread.Sleep(3000);
browser.Refresh();
// Find Username edit box using Xpath
IEditField userName = browser.Describe<IEditField>(new EditFieldDescription
{
XPath = "//input[@id='j_username']"
});
userName.SetValue("TEST");
Thread.Sleep(3000);
// Find password edit box using Xpath
IEditField password = browser.Describe<IEditField>(new EditFieldDescription
{
XPath = "//input[@id='j_password']"
});
password.SetValue("TEST");
Thread.Sleep(3000);
IButton submit = browser.Describe<IButton>(new ButtonDescription
{
XPath = "//*[@id='login-button']"
});
submit.Click();
browser.FullScreen();
Image img = browser.GetSnapshot();
Reporter.ReportEvent("Screenshot of failure", "", Status.Passed, img);
Thread.Sleep(3000);
}
catch (Exception e)
{
Assert.Fail("Unexpected Error Occurred while= " + e.Message);
}
}
[TestCleanup]
public void TestCleanup()
{
browser.Close();
}
[ClassCleanup]
public static void ClassCleanup()
{
GlobalTearDown();
}
}
}
您应该使用process.Start
启动Chrome,然后使用browser.Attach
到描述以附加到打开的浏览器。
这是大致的想法:
using System.Diagnostics;
...
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = "-incognito www.somesite.com";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
BrowserFactory.Attach(new BrowserDescription
{
Url = "www.somesite.com"
});
...
但正如Motti 在评论中所说,如果没有启用LeanFT扩展, Attach
将无法工作 - 这在隐身模式下被禁用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.