/// <summary>
        /// Performs the initialize of the browser.
        /// </summary>
        /// <param name="driverFolder">The driver folder.</param>
        /// <param name="proxy">The proxy.</param>
        /// <returns>
        /// The web driver.
        /// </returns>
        protected override IWebDriver PerformInitialize(string driverFolder, Proxy proxy)
        {
            var options = new PhantomJSOptions();
            options.AddAdditionalCapability(CapabilityType.Proxy, proxy);

            return new PhantomJSDriver(driverFolder, options);
        }
Example #2
0
 private Jenkins()
 {
     var options = new PhantomJSOptions();
     options.AddAdditionalCapability("phantomjs.page.customHeaders.Accept-Language", "en");
     _driver = new PhantomJSDriver(options);
     _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
 }
Example #3
0
 private Jenkins()
 {
     var options = new PhantomJSOptions();
     options.AddAdditionalCapability("phantomjs.page.customHeaders.Accept-Language", "en");
     _driver = new PhantomJSDriver(options);
     _wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10));
     var jenkinsUrl = Environment.GetEnvironmentVariable("JENKINS_URL");
     Url = string.IsNullOrEmpty(jenkinsUrl) ? "http://localhost:8080" : jenkinsUrl;
 }
        /// <summary>
        /// Sets up a customized instance of PhantomJS with regards to log level, command window visibility and timeouts.
        /// </summary>
        /// <returns>The PhantomJSDriver instance with customized configuration.</returns>
        public static PhantomJSDriver GetConfiguredPhantomJsDriver(int timeoutInSeconds)
        {
            PhantomJSDriverService phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
            phantomJsDriverService.HideCommandPromptWindow = true;
            PhantomJSOptions options = new PhantomJSOptions();
            options.AddAdditionalCapability("phantomjs.cli.args", new String[] { "--webdriver-loglevel=ERROR" });

            PhantomJSDriver phantomJsDriver = new PhantomJSDriver(phantomJsDriverService, options);
            phantomJsDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(timeoutInSeconds));
            return phantomJsDriver;
        }
        public static IWebDriver CreateWebDriver()
        {
            var proxyHost = AppSettingsHelper.ReadString(AppSettings.Proxy);
            var proxyPort = AppSettingsHelper.ReadInt(AppSettings.ProxyPort);
            var proxyString = $"{proxyHost}:{proxyPort}";

            var proxy = new Proxy
            {
                HttpProxy = proxyString,
                FtpProxy = proxyString,
                SslProxy = proxyString
            };

            var phantomJsOptions = new PhantomJSOptions();
            phantomJsOptions.AddAdditionalCapability(CapabilityType.Proxy, proxy);

            var driver = new PhantomJSDriver(phantomJsOptions);
            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));

            return driver;
        }
        public IpModuleManager(IpModule module)
        {
            string[] phantomArgs = new string[] { "--webdriver-loglevel=NONE" };

            PhantomJSOptions options = new PhantomJSOptions();
            options.AddAdditionalCapability("phantomjs.cli.args", phantomArgs);

            Module = module;
            var driverService = PhantomJSDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;
            driverService.LogFile = "phantomJSService.log";

            driver = new PhantomJSDriver(driverService, options);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            loginUrl = string.Format("{0}/login_page.html", Module.Url.Value.ToString());
            logoutUrl = string.Format("{0}/logout.html", Module.Url.Value.ToString());
            versionUrl = string.Format("{0}/version.html", Module.Url.Value.ToString());
            eventUrl = string.Format("{0}/event.html", Module.Url.Value.ToString());
            statusLiveUrl = string.Format("{0}/statuslive.html", Module.Url.Value.ToString());

            Devices = new List<Device>();
        }
Example #7
0
        private static IWebDriver CreatePhantomJsDriver(CrawlConfiguration p_Config)
        {
            // Optional options passed to the PhantomJS process.
            PhantomJSOptions options = new PhantomJSOptions();
            options.AddAdditionalCapability("phantomjs.page.settings.userAgent", p_Config.UserAgentString);
            options.AddAdditionalCapability("phantomjs.page.settings.javascriptCanCloseWindows", false);
            options.AddAdditionalCapability("phantomjs.page.settings.javascriptCanOpenWindows", false);
            options.AddAdditionalCapability("acceptSslCerts", !p_Config.IsSslCertificateValidationEnabled);

            // Basic auth credentials.
            options.AddAdditionalCapability("phantomjs.page.settings.userName", p_Config.LoginUser);
            options.AddAdditionalCapability("phantomjs.page.settings.password", p_Config.LoginPassword);

            // Create the service while hiding the prompt window.
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = true;
            IWebDriver driver = new PhantomJSDriver(service, options);

            return driver;
        }
Example #8
0
 private static PhantomJSOptions GetPhantomJsOptions()
 {
     PhantomJSOptions option = new PhantomJSOptions();
     option.AddAdditionalCapability("handlesAlerts", true);
     return option;
 }
        public IWebDriver StartPhantomJSBrowser()
        {
            var options = new PhantomJSOptions();

            if (Config.Settings.httpProxy.useProxy)
            {
                var proxy = new OpenQA.Selenium.Proxy();
                proxy.HttpProxy = Config.Settings.httpProxy.proxyUrl + ":" + TestBase.proxy.proxyPort;
                proxy.SslProxy = Config.Settings.httpProxy.proxyUrl + ":" + TestBase.proxy.proxyPort;
                proxy.FtpProxy = Config.Settings.httpProxy.proxyUrl + ":" + TestBase.proxy.proxyPort;
                options.AddAdditionalCapability("proxy", proxy);
            }

            return new PhantomJSDriver(options);
        }
Example #10
0
        private PhantomJSDriver getWebBrowserDriverInit()
        {
            // to run service in the bg - more convenient for end user (BUT, phatomjs.exe must be in same directory as WF executable)
            var driverService = PhantomJSDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), "phantomjs.exe");
            driverService.HideCommandPromptWindow = true;

            // emulate Mozzila/Chrome behaviour (env)
            PhantomJSOptions options = new PhantomJSOptions();
            options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36");

            return new PhantomJSDriver(driverService, options);
        }
        /*
         * 
         * METHODS
         * 
         */


        /// <summary>
        /// Main "Work" Thread
        /// Does all scraping work. To be used in another Thread to prevent Form locking.
        /// </summary>
        private void doScrapingWork()
        {
            // Clear output window
            this.setText("");

            // Check if the webClient has already been initialized
            if (this.webClient != null)
            {
                // If so close WebClient
                this.appendText("Closing WebClient!" + Environment.NewLine);
                webClient.Quit();
            }

            // Checks if Debug mode boolean is set
            if (debug)
            {
                // Set Debug WebClient if so

                // Set WebClient Service options
                srvc = ChromeDriverService.CreateDefaultService();
                srvc.HideCommandPromptWindow = true;

                // Initialize WebClient
                this.appendText("Starting WebClient" + Environment.NewLine);
                webClient = new ChromeDriver((ChromeDriverService)srvc);
            }
            else
            {
                // Set Regular WebClient if not

                // Set WebClient Service options
                srvc = PhantomJSDriverService.CreateDefaultService();
                srvc.HideCommandPromptWindow = true;

                // Set WebClient options
                PhantomJSOptions opts = new PhantomJSOptions();
                opts.AddAdditionalCapability("web-security", false);
                opts.AddAdditionalCapability("ssl-protocol", "any");
                opts.AddAdditionalCapability("ignore-ssl-errors", true);
                opts.AddAdditionalCapability("webdriver-loglevel", "DEBUG");

                // Initialize WebClient
                this.appendText("Starting WebClient" + Environment.NewLine);
                webClient = new PhantomJSDriver((PhantomJSDriverService)srvc, opts);
            }

            // Set WebClient pag load timeout to 10 seconds
            webClient.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 0, 10));

            // Open DC MyCampus login page
            this.appendText("Loading MyCampus login page" + Environment.NewLine);
            webClient.Navigate().GoToUrl("http://www.durhamcollege.ca/mycampus/");

            // Pass username and password to page
            this.appendText("Inputting login details" + Environment.NewLine);
            webClient.ExecuteScript("document.cplogin.user.value='" + txtUsername.Text + "';");
            webClient.ExecuteScript("document.cplogin.pass.value='" + txtPassword.Text + "';");

            // Click login button
            this.appendText("Logging in" + Environment.NewLine);
            webClient.FindElement(By.Id("submit-text-search")).Click();

            // Set Campus based on ComboBox
            string homeAnchorText;

            switch (this.getCampusSelection())
            {
                case "Durham College":
                    homeAnchorText = "DC Home";
                    break;
                case "UOIT":
                    homeAnchorText = "UOIT Home";
                    break;
                default:
                    homeAnchorText = "DC Home";
                    break;
            }

            // Search for Campus "Home" Anchor
            IReadOnlyCollection<IWebElement> homeAnchor = webClient.FindElements(By.LinkText(homeAnchorText));

            // Check if login succeeded based on the "Home" Anchor
            if (homeAnchor.Count > 0)
            {
                // Click Anchor to load Student Information
                webClient.FindElement(By.LinkText(homeAnchorText)).Click();

                this.appendText("Login successful" + Environment.NewLine);
            }
            else
            {
                // Login unsuccessful
                this.appendText("Login Unsuccessful!" + Environment.NewLine);

                // Enable go button
                this.setButtonEnabled(true);

                // End Thread
                return;
            }

            // Select / Click Timetable Anchor
            this.appendText("Clicking 'Student schedule' link" + Environment.NewLine);
            webClient.FindElement(By.LinkText("Student schedule by day and time")).Click();

            // Select Timetable IFrame
            this.appendText("Switch to Content IFrame" + Environment.NewLine);
            webClient.SwitchTo().Frame("content");

            // Select / Click Second Timetable Anchor 
            this.appendText("Clicking Second 'Student schedule' link" + Environment.NewLine);
            webClient.FindElement(By.PartialLinkText("Student Schedule")).Click();

            // Create empty Calendar with default settings
            this.appendText("Initialize blank ICalendar" + Environment.NewLine);
            iCalendar ical = new iCalendar();

            // Set required properties to the Calendar
            this.appendText("Set ICalendar properties" + Environment.NewLine);
            ical.ProductID = "-//Scott Chi//iCalendar 1.0//EN";
            ical.Version = "2.0";
            ical.Scale = "GREGORIAN";

            // Initialize 
            this.appendText("Initialize Dictionary" + Environment.NewLine);
            Dictionary<string, Dictionary<string, string>> calendarMap = new Dictionary<string, Dictionary<string, string>>();

            int lastPage = 0;

            // Add all classes in the week
            this.appendText("Start grabbing class info from each week" + Environment.NewLine);
            do
            {
                // Grab Weekstart from Timetable IFrame
                String weekStart = webClient.FindElement(By.XPath("//span[@class='fieldlargetext']")).Text.Substring(8);

                // Loop through Timetable Anchors
                foreach (var calendarAnchor in webClient.FindElements(By.XPath("//table[@class='bordertable']/tbody//tr//td//a")))
                {
                    // Grab class from Anchor
                    string clss = calendarAnchor.Text.Split('\r')[0];
                    // Grab Anchor Link from Anchor
                    string href = calendarAnchor.GetAttribute("href");

                    // Check if there are keys for this week yet
                    if (!calendarMap.ContainsKey(weekStart))
                    {
                        // If not initialize week in Dictionary
                        calendarMap.Add(weekStart, new Dictionary<string, string>());
                    }

                    // Check if the class has already been added to the week entry
                    if (calendarMap.ContainsKey(weekStart) && calendarMap[weekStart].ContainsKey(clss))
                    {
                        // If so skip it
                        continue;
                    }

                    // Add class to week
                    calendarMap[weekStart].Add(clss, href);
                }

                IReadOnlyCollection<IWebElement> nextPage = webClient.FindElements(By.XPath("//table[@class='plaintable']/tbody//tr//p[@class='rightaligntext']//a"));

                // Check if this is last page
                if (nextPage.Count > 0)
                {
                    // If not click to next page
                    nextPage.First().Click();
                }

                // Check if next week will be last week
                if (webClient.FindElements(By.XPath("//table[@class='plaintable']/tbody//tr//p[@class='rightaligntext']//a")).Count == 0)
                {
                    // If so increment the last page (only works once)
                    lastPage++;
                    continue;
                }
            }
            // While there is a "Next Week" or if page is the "Last Page" anchor add all classes in week
            while (webClient.FindElements(By.XPath("//table[@class='plaintable']/tbody//tr//p[@class='rightaligntext']//a")).Count > 0 || lastPage == 1);

            // Intitilize week count
            int weekCount = 1;

            // Loop through weeks
            this.appendText("Loop through grabbed data" + Environment.NewLine);
            foreach (KeyValuePair<string, Dictionary<string, string>> dictEntry in calendarMap)
            {
                this.appendText("Parsing information from week " + weekCount + Environment.NewLine);

                // Grab week start date
                string weekStart = dictEntry.Key;

                // Loop through classes
                foreach (KeyValuePair<string, string> entry in dictEntry.Value)
                {
                    // Initialize class name
                    string clss = entry.Key;

                    // Go to class url
                    webClient.Navigate().GoToUrl(entry.Value);

                    // Initialize time, room, teacherName variables
                    string time = "", room = "", teacherName = "";

                    // Loop through Timetable rows
                    foreach (var row in webClient.FindElements(By.XPath("//table[@class='bordertable' and caption/.='Scheduled Meeting Times']/tbody//tr")))
                    {
                        // Check if row is header row or if this class has already been added if either is true continue loop
                        if (row.Text.Contains("Type"))
                        {
                            continue;
                        }

                        // Initialize row counter and date advancer
                        int i = 0, advDate = 0;

                        // Loop through row cells
                        foreach (var dataCell in row.FindElements(By.TagName("td")))
                        {
                            // Switch that checks which column the data corresponds to
                            switch (i)
                            {
                                // Type of class, not currently used
                                case 0:
                                    break;
                                // Time field
                                case 1:
                                    time = dataCell.Text;
                                    break;
                                // Days of week field
                                case 2:
                                    // Initialize dayOfWeek variable
                                    String dayOfWeek = dataCell.Text;
                                    // Switch that checks which day of the week it is
                                    // Changes date advancer to match day of week
                                    // e.g. Monday = no advancement, Tuesday = one day advancement
                                    switch (dayOfWeek)
                                    {
                                        case "M":
                                            break;
                                        case "T":
                                            advDate = 1;
                                            break;
                                        case "W":
                                            advDate = 2;
                                            break;
                                        case "R":
                                            advDate = 3;
                                            break;
                                        case "F":
                                            advDate = 4;
                                            break;
                                    }
                                    break;
                                // Room field
                                case 3:
                                    room = dataCell.Text;
                                    break;
                                // Date range field, not currently in use
                                case 4:
                                    break;
                                // Schedule type field, not currently used
                                case 5:
                                    //scheduleType = dataCell.getTextContent();
                                    break;
                                // Teacher name field
                                case 6:
                                    teacherName = dataCell.Text.Split('(')[0].Trim();
                                    break;
                            }

                            // Increment row counter
                            i++;
                        }

                        // Create the Events title class name with room number in parentheses
                        String[] classArray = room.Split(' ');
                        String title = clss + "(" + classArray[classArray.Length - 1] + ")";
                        // Create the Events description each item is on a new line
                        // Includes class name, time of class, room number, teachers name
                        String description = clss + Environment.NewLine + time + Environment.NewLine + room + Environment.NewLine + teacherName;

                        // Create a Date formatter that will be used to format a time string
                        //string format = "MMM dd, yyyy hh:mm aa";

                        // Split the time range
                        String[] splitTime = time.Split('-');

                        // Add the start and end times to the date, parse it and convert it to a Date object
                        DateTime startDate;
                        DateTime endDate;

                        if (!(DateTime.TryParse(weekStart + " " + splitTime[0].Trim(), out startDate) &&
                        DateTime.TryParse(weekStart + " " + splitTime[1].Trim(), out endDate)))
                        {
                            //TODO Print Message.
                            return;
                        }

                        // Add the date advance to the date
                        // 86400000 milliseconds = 1 day = 24 hours
                        DateTime startDateTime = startDate.AddDays(advDate);
                        DateTime endDateTime = endDate.AddDays(advDate);

                        // Pass variables to add event to calendar function
                        addEventToCalendar(ical, startDateTime, endDateTime, description, title);
                    }
                }

                this.appendText(dictEntry.Value.Count + " events added from week " + weekCount + Environment.NewLine);

                weekCount++;
            }

            // Write calendar to file
            this.appendText(ical.Calendar.Events.Count + " events being written to file" + Environment.NewLine + "'" + txtFileLocation.Text + "'" + Environment.NewLine);
            iCalendarSerializer serializer = new iCalendarSerializer();
            serializer.Serialize(ical, txtFileLocation.Text);

            // Quite WebClient
            this.appendText("Closing WebClient!" + Environment.NewLine);
            webClient.Quit();

            // Enable Go button
            this.setButtonEnabled(true);
        }
Example #12
0
        public static IWebDriver CreatePhantomDriver()
        {
            PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
            //service.IgnoreSslErrors = true;
            //service.LoadImages = false;
            //service.ProxyType = "none";
            //service.SslProtocol = "tlsv1"; //"any" "tlsv1"

            PhantomJSOptions opts = new PhantomJSOptions();
            opts.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36");

            var PhantomDriver = new PhantomJSDriver(service, opts);

            PhantomDriver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
            PhantomDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
            return PhantomDriver;
        }
 private static PhantomJSOptions GetPhantomJsptions()
 {
     var option = new PhantomJSOptions();
     option.AddAdditionalCapability("handlesAlerts", true);
     Logger.Info("Using PhantomJSOptions");
     return option;
 }
Example #14
-2
        public StepContext(int bankId)
        {
            using (var db = new Entities())
            {
                // To Do: Init TransactionModel
                //this.TransactionModel = 
                this.BankId = bankId;
                var bank = db.Banks.Where(x => x.Id == bankId).FirstOrDefault();
                if(bank != null)
                {
                    
                    switch (bank.WebBrowser.Name.ToLower())
                    {
                        case "chrome":
                            WebDriver = new ChromeDriver();
                            break;
                        case "phantomjs":
                            PhantomJSOptions options = new PhantomJSOptions();
                            if (!string.IsNullOrWhiteSpace(bank.UserAgent))
                            {
                                //"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"
                                options.AddAdditionalCapability("phantomjs.page.settings.userAgent", bank.UserAgent);
                            }
                            PhantomJSDriverService defaultService = PhantomJSDriverService.CreateDefaultService();
                            defaultService.HideCommandPromptWindow = true;
                            defaultService.LoadImages = false;
                            WebDriver = new PhantomJSDriver(defaultService, options);
                            break;
                        default:
                            WebDriver = new ChromeDriver();
                            break;
                    }
                    
                    WaitDriver = new WebDriverWait(WebDriver, new TimeSpan(0, 0, bank.TimeOut.Value));
                    ShortWaitDriver = new WebDriverWait(WebDriver, new TimeSpan(0, 0, bank.TimeOut.Value / 2));

                    httpClient = new HttpClient() { Timeout = new TimeSpan(0, 0, bank.TimeOut.Value) };
                    TransactionModel = new BankTransaction();
                }
            }
        }