LeanFT在隐身模式下打开浏览器

4
问题:很遗憾,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();
    }
}
}

2
我不确定为什么您想要在隐身模式下运行浏览器,但即使您成功了,您也需要在隐身模式下启用Chrome的功能测试代理扩展程序,以便能够与浏览器进行交互。 - Motti
1个回答

0

你应该使用 process.Start 来启动 Chrome,然后使用 browser.Attachdescription 附加到已打开的浏览器。

大致思路如下:

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在评论中所说, Attach将无法工作,除非启用了LeanFT扩展 - 而该扩展在隐身模式下被禁用


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接