【问题标题】:LeanFT Opening Browser in Incognito ModeLeanFT 以隐身模式打开浏览器
【发布时间】:2019-03-26 17:39:03
【问题描述】:

问题:不幸的是,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();
    }
}
}

【问题讨论】:

  • 我不知道你为什么要在隐身模式下运行浏览器,但即使你成功了,你也需要在隐身模式下启用 Chrome Functional Testing Agent 扩展为了能够与浏览器进行交互。

标签: c# google-chrome incognito-mode leanft


【解决方案1】:

您应该使用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 said in the commentsAttach 在没有启用 LeanFT 扩展的情况下将无法工作 - 在隐身模式下被禁用

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 2017-05-20
    • 2013-10-02
    相关资源
    最近更新 更多