コード例 #1
0
        public void Chrome_Logotypy()
        {
            /* Preparing a folder for downloading the .zip file */

            string downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\seleniumTest";
            string fileName          = downloadDirectory + "\\logotypy.zip";

            if (!Directory.Exists(downloadDirectory))
            {
                Directory.CreateDirectory(downloadDirectory);
            }
            else
            {
                string[] filesList = Directory.GetFiles(downloadDirectory);

                foreach (string file in filesList)
                {
                    File.Delete(file);
                }

                Directory.Delete(downloadDirectory);
                Directory.CreateDirectory(downloadDirectory);
            }

            ChromeOptions chromeOptions = new ChromeOptions();

            chromeOptions.AddUserProfilePreference("download.default_directory", downloadDirectory);

            /* Initializing chromedriver */

            IWebDriver driver = new ChromeDriver(chromeOptions);

            driver.Manage().Window.Maximize();

            driver.Navigate().GoToUrl("https://www.medicalgorithmics.pl/");

            /* Initializing instance of a MainPage object which represent main page of Medicalgorithmics site */

            MainPage mainPage = new MainPage(driver);

            Assert.False(mainPage.GetLoadingError());

            mainPage.AcceptCookies();

            string buttonColorBeforeFocusing = mainPage.GetContactColor();

            mainPage.ContactGoTo(driver);

            /* Test for changing color of the "Kontakt" button */

            string buttonColorAfterFocusing = mainPage.GetContactColor();

            Assert.NotEqual(buttonColorBeforeFocusing, buttonColorAfterFocusing);

            mainPage.ContactClick();

            /* Initializing instance of the ContactPage class which represents "Kontakt" page */

            ContactPage contactPage = new ContactPage(driver);

            Assert.Equal("https://www.medicalgorithmics.pl/kontakt", driver.Url);

            Assert.False(contactPage.GetLoadingError());
            contactPage.ScrollToTheMediaPack(driver);

            Thread.Sleep(3000);

            contactPage.MediaPackClick();
            Assert.Equal("https://www.medicalgorithmics.pl/media-pack", driver.Url);

            /* Initializing instance of the MediaPackPage class which represents Media Pack page */

            MediaPackPage mediaPackPage = new MediaPackPage(driver);

            Assert.False(mediaPackPage.GetLoadingError());

            Assert.False(File.Exists(fileName));
            Thread.Sleep(3000);

            /* Downloading logotypy.zip file and checking if the file downloaded correctly into given directory */

            mediaPackPage.DonwloadLogotypy();

            int i = 0;

            while (!File.Exists(fileName) && i < 20000)
            {
                Thread.Sleep(1);
                i++;
            }

            Assert.True(File.Exists(fileName));

            /* Deleteing downloaded file and created directory */

            File.Delete(fileName);
            Directory.Delete(downloadDirectory);

            driver.Close();
        }
コード例 #2
0
        public void Firefox_Logotypy()
        {
            /* Preparing a folder for downloading the .zip file */

            string downloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\seleniumTest";
            string fileName          = downloadDirectory + "\\logotypy.zip";

            if (!Directory.Exists(downloadDirectory))
            {
                Directory.CreateDirectory(downloadDirectory);
            }
            else
            {
                string[] filesList = Directory.GetFiles(downloadDirectory);

                foreach (string file in filesList)
                {
                    File.Delete(file);
                }

                Directory.Delete(downloadDirectory);
                Directory.CreateDirectory(downloadDirectory);
            }

            FirefoxOptions profile = new FirefoxOptions();

            profile.SetPreference("browser.download.manager.showWhenStarting", false);
            profile.SetPreference("browser.download.dir", downloadDirectory);
            profile.SetPreference("browser.download.folderList", 2);
            profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
            profile.SetPreference("browser.download.useDownloadDir", true);

            /* Initializing firefoxdriver */

            IWebDriver driver = new FirefoxDriver(profile);

            driver.Manage().Window.Maximize();

            driver.Navigate().GoToUrl("https://www.medicalgorithmics.pl/");

            /* Initializing instance of a MainPage object which represent main page of Medicalgorithmics site */

            MainPage mainPage = new MainPage(driver);

            Assert.False(mainPage.GetLoadingError());

            mainPage.AcceptCookies();

            string buttonColorBeforeFocusing = mainPage.GetContactColor();

            mainPage.ContactGoTo(driver);

            /* Test for changing color of the "Kontakt" button (For Firefox I disabled this test as the Actions class is not working for Gecko driver and the issue is not solved yet) */

            string buttonColorAfterFocusing = mainPage.GetContactColor();

            //Assert.NotEqual(buttonColorBeforeFocusing, buttonColorAfterFocusing);

            mainPage.ContactClick();

            /* Initializing instance of the ContactPage class which represents "Kontakt" page */

            ContactPage contactPage = new ContactPage(driver);

            Assert.Equal("https://www.medicalgorithmics.pl/kontakt", driver.Url);

            Assert.False(contactPage.GetLoadingError());
            contactPage.ScrollToTheMediaPack(driver);

            Thread.Sleep(3000);

            contactPage.MediaPackClick();
            Assert.Equal("https://www.medicalgorithmics.pl/media-pack", driver.Url);

            /* Initializing instance of the MediaPackPage class which represents Media Pack page */

            MediaPackPage mediaPackPage = new MediaPackPage(driver);

            Assert.False(mediaPackPage.GetLoadingError());

            Assert.False(File.Exists(fileName));
            Thread.Sleep(3000);

            /* Downloading logotypy.zip file and checking if the file downloaded correctly into given directory */

            mediaPackPage.DonwloadLogotypy();

            int i = 0;

            while (!File.Exists(fileName) && i < 20000)
            {
                Thread.Sleep(1);
                i++;
            }

            Assert.True(File.Exists(fileName));

            /* Deleteing downloaded file and created directory */

            File.Delete(fileName);
            Directory.Delete(downloadDirectory);

            driver.Close();
        }