4

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();
    }
}
}
BK Hasan
  • 121
  • 1
  • 1
  • 9
  • 2
    I'm not sure why you want to run your browser in incognito mode but even if you're successful you will need to enable the Chrome *Functional Testing Agent* extension in incognito in order to be able to interact with the browser. – Motti Oct 23 '18 at 13:11

1 Answers1

0

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

Adelin
  • 7,809
  • 5
  • 37
  • 65