简体   繁体   中英

LeanFT Opening Browser in Incognito Mode

Problem: LeanFT in C# doesn't have a way to open the browser in incognito mode unfortunately. I am unable to add -incognito to path as I don't have admin rights. What can I do? I was thinking Sendkeys(“^+N”); but not sure how to do that via keyboard or if it would work as browser is already instantiated.

Has anyone else run into this problem? It's really cumbersome like I said since LeanFT doesn't allow incognito mode to be runned automatically.

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();
    }
}
}

You should use process.Start to start Chrome, and browser.Attach to a description to attach to the opened browser.

Here's the idea roughly:

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"
});
...

But as Motti said in the comments , Attach will not work without the LeanFT extension enabled - which is disabled in incognito

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM