示例#1
0
 public void TestInitialize()
 {
     this.browser   = new BrowserSession();
     this.vpnClient = new FirefoxPrivateVPNSession();
     this.desktop   = new DesktopSession();
     Utils.RearrangeWindows(this.vpnClient, this.browser);
 }
示例#2
0
        public void TestInitialize()
        {
            this.folderPath    = "C:/Temp";
            this.debugFileName = "test.zip";
            this.logFileName   = "test.txt";
            if (!Directory.Exists(this.folderPath))
            {
                Directory.CreateDirectory(this.folderPath);
            }

            // check the file exists or not. If already existed then delete it.
            foreach (string fileName in new List <string> {
                this.debugFileName, this.logFileName
            })
            {
                string fullPath = Path.Combine(this.folderPath, fileName);
                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            this.browser   = new BrowserSession();
            this.vpnClient = new FirefoxPrivateVPNSession();
            this.desktop   = new DesktopSession();
            Utils.RearrangeWindows(this.vpnClient, this.browser);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FirefoxPrivateVPNSession"/> class.
        /// </summary>
        public FirefoxPrivateVPNSession()
        {
            if (this.Session == null)
            {
                // Create a new session to bring up an instance of the FirefoxPrivateNetworkVPN application
                DesiredCapabilities appCapabilities = new DesiredCapabilities();
                appCapabilities.SetCapability("app", FirefoxPrivateVPNAppId);
                appCapabilities.SetCapability("deviceName", "WindowsPC");

                try
                {
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                    Assert.IsNotNull(this.Session);
                }
                catch (Exception)
                {
                    // 1. Creating a Desktop session
                    var           desktopSession = new DesktopSession();
                    WebDriverWait wait           = new WebDriverWait(desktopSession.Session, TimeSpan.FromSeconds(30));
                    var           firefoxVPN     = wait.Until(ExpectedConditions.ElementExists(By.Name("Firefox Private Network VPN")));

                    // 2. Attaching to existing firefox Window
                    string applicationSessionHandle = firefoxVPN.GetAttribute("NativeWindowHandle");
                    applicationSessionHandle = int.Parse(applicationSessionHandle).ToString("x");

                    appCapabilities.SetCapability("app", null);
                    appCapabilities.SetCapability("appTopLevelWindow", applicationSessionHandle);
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                    Assert.IsNotNull(this.Session);
                }

                // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
                this.Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
            }
        }
        public void TestInitialize()
        {
            this.folderPath    = "C:/Temp";
            this.debugFileName = "test.zip";
            this.logFileName   = "test.txt";
            if (!Directory.Exists(this.folderPath))
            {
                Directory.CreateDirectory(this.folderPath);
            }

            // check the file exists or not. If already existed then delete it.
            foreach (string fileName in new List <string> {
                this.debugFileName, this.logFileName
            })
            {
                string fullPath = Path.Combine(this.folderPath, fileName);
                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            this.browser   = new BrowserSession();
            this.vpnClient = new FirefoxPrivateVPNSession();
            this.desktop   = new DesktopSession();

            // Resize browser to make vpn client and browser are not overlapped
            var vpnClientPosition = this.vpnClient.Session.Manage().Window.Position;
            var vpnClientSize     = this.vpnClient.Session.Manage().Window.Size;

            this.browser.SetWindowPosition(vpnClientPosition.X + vpnClientSize.Width, 0);
        }
示例#5
0
        /// <summary>
        /// User click the toggle switch to connect to VPN.
        /// </summary>
        /// <param name="vpnClient">VPN session.</param>
        /// <param name="desktop">Desktop session.</param>
        public static void ConnectVPN(FirefoxPrivateVPNSession vpnClient, DesktopSession desktop)
        {
            // Click VPN switch toggle and turn on VPN
            vpnClient.Session.SwitchTo();
            MainScreen mainScreen = new MainScreen(vpnClient.Session);

            Assert.AreEqual("VPN is off", mainScreen.GetTitle());
            Assert.AreEqual("Turn it on to protect your entire device", mainScreen.GetSubtitle());
            Assert.IsTrue(mainScreen.GetOffImage().Displayed);
            Assert.IsFalse(mainScreen.GetOnImage().Displayed);
            mainScreen.ToggleVPNSwitch();

            // Verify the windows notification
            desktop.Session.SwitchTo();
            WindowsNotificationScreen windowsNotificationScreen = new WindowsNotificationScreen(desktop.Session);

            Assert.AreEqual("VPN is on", windowsNotificationScreen.GetTitleText());
            Assert.AreEqual("You're secure and protected.", windowsNotificationScreen.GetMessageText());
            windowsNotificationScreen.ClickDismissButton();

            // Verify user is connected to Mullvad VPN
            IRestResponse response = Utils.AmIMullvad("You are connected to Mullvad");

            Console.WriteLine($"After connection - Mullvad connected API response: {response.Content}");
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsTrue(response.Content.Contains("You are connected to Mullvad"));

            // Verify the changes on main screen
            vpnClient.Session.SwitchTo();
            Assert.IsTrue(mainScreen.GetOnImage().Displayed);
            Assert.IsFalse(mainScreen.GetOffImage().Displayed);
            Assert.AreEqual("VPN is on", mainScreen.GetTitle());
            Assert.IsTrue(mainScreen.GetSubtitle().Contains("Secure and protected"));
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BrowserSession"/> class.
        /// </summary>
        public BrowserSession()
        {
            if (this.Session == null)
            {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.SetCapability("platormName", "Windows");
                capabilities.SetCapability("deviceName", "WindowsPC");
                capabilities.SetCapability("app", BrowserAppId);
                try
                {
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), capabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                    Assert.IsNotNull(this.Session);
                }
                catch (Exception)
                {
                    // 1. Creating a Desktop session
                    var desktopSession = new DesktopSession();
                    var firefoxWindows = Utils.WaitUntilFindElement(desktopSession.Session.FindElementByClassName, "MozillaWindowClass");

                    // 2. Attaching to existing firefox Window
                    string applicationSessionHandle = firefoxWindows.GetAttribute("NativeWindowHandle");
                    applicationSessionHandle = int.Parse(applicationSessionHandle).ToString("x");
                    DesiredCapabilities appCapabilities = new DesiredCapabilities();
                    appCapabilities.SetCapability("deviceName", "WindowsPC");
                    appCapabilities.SetCapability("appTopLevelWindow", applicationSessionHandle);
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                }

                // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
                this.Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
            }
        }
示例#7
0
        public void TestInitialize()
        {
            this.browser   = new BrowserSession();
            this.vpnClient = new FirefoxPrivateVPNSession();
            this.desktop   = new DesktopSession();

            // Resize browser to make vpn client and browser are not overlapped
            var vpnClientPosition = this.vpnClient.Session.Manage().Window.Position;
            var vpnClientSize     = this.vpnClient.Session.Manage().Window.Size;

            this.browser.SetWindowPosition(vpnClientPosition.X + vpnClientSize.Width, 0);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BrowserSession"/> class.
        /// </summary>
        public BrowserSession()
        {
            if (this.Session == null)
            {
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.SetCapability("platormName", "Windows");
                capabilities.SetCapability("deviceName", "WindowsPC");
                capabilities.SetCapability("app", BrowserAppId);
                try
                {
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), capabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                    Assert.IsNotNull(this.Session);
                }
                catch (Exception)
                {
                    // 1. Creating a Desktop session
                    var         desktopSession = new DesktopSession();
                    bool        retry          = true;
                    int         retryTimes     = 0;
                    IWebElement firefoxWindows = null;
                    while (retry)
                    {
                        retryTimes += 1;
                        WebDriverWait wait = new WebDriverWait(desktopSession.Session, TimeSpan.FromSeconds(60));
                        firefoxWindows = wait.Until(ExpectedConditions.ElementExists(By.ClassName("MozillaWindowClass")));
                        if (firefoxWindows == null)
                        {
                            retry = true;
                            if (retryTimes == 5)
                            {
                                throw new Exception("Unable to launch firefox browser");
                            }
                        }
                        else
                        {
                            retry = false;
                        }
                    }

                    // 2. Attaching to existing firefox Window
                    string applicationSessionHandle = firefoxWindows.GetAttribute("NativeWindowHandle");
                    applicationSessionHandle = int.Parse(applicationSessionHandle).ToString("x");
                    DesiredCapabilities appCapabilities = new DesiredCapabilities();
                    appCapabilities.SetCapability("deviceName", "WindowsPC");
                    appCapabilities.SetCapability("appTopLevelWindow", applicationSessionHandle);
                    this.Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(Constants.SessionTimeoutInSeconds));
                }

                // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
                this.Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
            }
        }
        /// <summary>
        /// Dispose the VPN session and close the app.
        /// </summary>
        public void Dispose()
        {
            // Close the application and delete the session
            if (this.Session != null)
            {
                this.Session.SwitchTo();
                try
                {
                    WindowsElement landingView = this.Session.FindElementByClassName("LandingView");
                }
                catch (InvalidOperationException)
                {
                    UserCommonOperation.UserSignOut(this);
                }

                this.Session.Quit();
                var desktopSession = new DesktopSession();
                desktopSession.CloseVPNClient();
                this.Session = null;
            }
        }