microsoft / EasyRepro

Automated UI testing API for Dynamics 365
MIT License
521 stars 288 forks source link

[BUG] Method not found: 'Void OpenQA.Selenium.Edge.EdgeOptions.set_UseInPrivateBrowsing(Boolean)'.' When using Edge on Windows 11 #1277

Open namurdock opened 2 years ago

namurdock commented 2 years ago

Bug Report

Issues should only be created for items related to covered functionality.

Not covered functionality, feature requests, and questions should use the Feature Request or Question templates.

EasyRepro Version

UCI or Classic Web

Online or On Premise

Browser

Describe the bug
All packages from NuGet:

Dynamics365.UIAutomation.Api: 9.2.21111.116-RW2-Preview Selenium.Support: 4.1.0 Selenium.WebDriver: 4.1.0

Note: When specifying Chrome as my browser everything works as expected.

When specifying Edge as my browser type the following code produces an error:


            options = options ?? TestSettings.Options;
            SetOptions(options);

            string url = Environment.GetEnvironmentVariable("CrmUrl");
            string user = Environment.GetEnvironmentVariable("CrmUsername");
            string pass = Environment.GetEnvironmentVariable("CrmPassword");

            xrmClient = new WebClient(options);
            xrmApp = new XrmApp(xrmClient);
            xrmApp.OnlineLogin.Login(new Uri(url), user.ToSecureString(), pass.ToSecureString());

Where TestSettings.Options is:

 public static BrowserOptions SharedOptions = new BrowserOptions
        {
            BrowserType = (BrowserType)Enum.Parse(typeof(BrowserType), "Edge"),
            PrivateMode = true,
            FireEvents = false,
            Headless = false,
            Kiosk = false,
            UserAgent = false,
            DefaultThinkTime = 2000,
            UCITestMode = true,
            UCIPerformanceMode = true,
            DriversPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
            DisableExtensions = false,
            DisableFeatures = false,
            DisablePopupBlocking = false,
            DisableSettingsWindow = false,
            EnableJavascript = false,
            NoSandbox = false,
            DisableGpu = false,
            DumpDom = false,
            EnableAutomation = false,
            DisableImplSidePainting = false,
            DisableDevShmUsage = false,
            DisableInfoBars = false,
            TestTypeBrowser = false
        };

Special formatting / display

Code to reproduce

xrmApp.OnlineLogin.Login(_xrmUri, _username, _password);

xrmApp.Navigation.OpenApp(UCIAppName.Sales);

xrmApp.Navigation.QuickCreate("contact");

xrmApp.QuickCreate.SetValue(new LookupItem() { Name = "parentcustomerid", Value = "Test" });

xrmApp.QuickCreate.Save();

Error returned by xrmApp.OnlineLogin.Login(new Uri(url), user.ToSecureString(), pass.ToSecureString());

System.MissingMethodException HResult=0x80131513 Message=Method not found: 'Void OpenQA.Selenium.Edge.EdgeOptions.set_UseInPrivateBrowsing(Boolean)'. Source=Microsoft.Dynamics365.UIAutomation.Browser StackTrace: at Microsoft.Dynamics365.UIAutomation.Browser.BrowserOptions.ToEdge() at Microsoft.Dynamics365.UIAutomation.Browser.BrowserDriverFactory.CreateWebDriver(BrowserOptions options) at Microsoft.Dynamics365.UIAutomation.Browser.InteractiveBrowser.get_Driver() at Microsoft.Dynamics365.UIAutomation.Browser.BrowserPage.Execute[TResult,T1,T2,T3,T4,T5](BrowserCommandOptions options, unc7 delegate, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) at Microsoft.Dynamics365.UIAutomation.Api.UCI.WebClient.Login(Uri orgUri, SecureString username, SecureString password, SecureString mfaSecretKey, Action1 redirectAction) at Microsoft.Dynamics365.UIAutomation.Api.UCI.OnlineLogin.Login(Uri orgUrl, SecureString username, SecureString password, SecureString mfaSecretKey)

Expected behavior
Expected behaviour is for a new Edge browser to launch in "Private" mode.

Screenshots

Additional context

tipsey commented 2 years ago

I am using the default TestSettings.Options and default MFA login public static BrowserOptions SharedOptions = new BrowserOptions { BrowserType = (BrowserType)Enum.Parse(typeof(BrowserType), Type), PrivateMode = UsePrivateMode, FireEvents = false, Headless = false, UserAgent = false, DefaultThinkTime = 2000, RemoteBrowserType = (BrowserType)Enum.Parse(typeof(BrowserType), RemoteType), RemoteHubServer = new Uri(RemoteHubServerURL), UCITestMode = true, UCIPerformanceMode = true, DriversPath = Path.IsPathRooted(DriversPath) ? DriversPath : Path.Combine(Directory.GetCurrentDirectory(), DriversPath), DisableExtensions = false, DisableFeatures = false, DisablePopupBlocking = false, DisableSettingsWindow = false, EnableJavascript = false, NoSandbox = false, DisableGpu = false, DumpDom = false, EnableAutomation = false, DisableImplSidePainting = false, DisableDevShmUsage = false, DisableInfoBars = false, TestTypeBrowser = false };

var client = new WebClient(TestSettings.Options); if (TestSettings.Options.Headless) client.Browser.Driver.Manage().Window.Size = new Size(1920, 1080); using (var xrmApp = new XrmApp(client)) { xrmApp.OnlineLogin.Login(_xrmUri, _username.ToSecureString(), _password.ToSecureString());

I made this change in BrowserOptions.cs

public virtual EdgeOptions ToEdge() { var options = new EdgeOptions()

        {
            PageLoadStrategy = PageLoadStrategy.Normal,

        };
        options.AddArgument("InPrivate");
        return options;
    }

I also had to copy the latest msedgedriver.exe iinto my solution and set to always copy to Output Directory

It seems to work for me, except my account using MFA must have certain security parameters.

Nathan15911512 commented 2 years ago

We are also facing the same issue. Unable to login through "InPrivate" mode in Edge, but in "Chrome" it's working fine. Also not able to implement the above solution ( options.AddArgument("InPrivate"); ) because "AddArgument" is not included in "EdgeOptions" and "EdgeOptions" is a metadata file so there is no option to edit.

Could someone help us with the solution?