/// <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);
        }
Esempio n. 2
0
	private Downloader()
	{	    
            if(Directory.Exists(TempOutputPath) == false)
            {
                Directory.CreateDirectory(TempOutputPath);
            }

            if(Directory.Exists(OutputPath) == false)
            {
                Directory.CreateDirectory(OutputPath);
            }

	    var service = PhantomJSDriverService.CreateDefaultService();
	    var options = new PhantomJSOptions();
	    	
	    _driver = new PhantomJSDriver(service, options, TimeSpan.FromSeconds(30));

	    _queue  = new Queue<ScrapeReq>();
	    
	    _scrapers = new Dictionary<string, IScraper>();
	    _scrapers.Add(KinomanScraper.Key, new KinomanScraper());
	    _scrapers.Add(WatchSeriesScraper.Key, new WatchSeriesScraper());
	    _scrapers.Add(WatchFreeScraper.Key, new WatchFreeScraper());

	    foreach(var scraper in _scrapers.Values)
	    {
		scraper.WebDriverError += OnWebDriverProgress;
		scraper.WebDriverProgress += OnWebDriverProgress;
	    }

	    _downloadProc = new Thread(DownloadProc);
	    _downloadProc.Start();	    	
    	}
Esempio n. 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));
 }
 private static ICapabilities ConvertOptionsToCapabilities(PhantomJSOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options", "options must not be null");
     }
     return(options.ToCapabilities());
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>.
        /// </summary>
        /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
        /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
        /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
        public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout)
            : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities())
        {
            // Add the custom commandInfo of PhantomJSDriver
            CommandInfo commandInfo = new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/phantom/execute");

            this.CommandExecutor.CommandInfoRepository.TryAddCommand(CommandExecutePhantomScript, commandInfo);
        }
Esempio n. 6
0
	public ScraperBase()
	{
	    if(_driver == null)
	    {
		var service = PhantomJSDriverService.CreateDefaultService();
		var options = new PhantomJSOptions();
		_driver = new PhantomJSDriver(service, options, TimeSpan.FromSeconds(30));
	    }
	}
Esempio n. 7
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;
 }
Esempio n. 8
0
        public PhantomJsFactory()
        {
            var option = new OSP.PhantomJSOptions();

            //var preferences = new KeyValuePair<string, object>("chrome.contentSettings.images", "block");

            //option.AddAdditionalCapability("chrome.prefs", preferences);

            _driver = new OSP.PhantomJSDriver(GetPhantomJSDriverService(), option);
        }
        /// <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;
        }
Esempio n. 10
0
        public void Start()
        {
            if (Selenium != null)
                return;

            var options = new PhantomJSOptions();
            //options.

            Selenium = new PhantomJSDriver();
            Selenium.Manage().Timeouts().ImplicitlyWait(DefaultTimeout);

            Trace("PhantomJS ready");
        }
Esempio n. 11
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;
        }
Esempio n. 12
0
        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>();
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified path
 /// to the directory containing PhantomJS.exe and options.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, PhantomJSOptions options)
     : this(phantomJSDriverServerDirectory, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified
 /// <see cref="PhantomJSDriverService"/> and options.
 /// </summary>
 /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options)
     : this(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities())
 {
 }
Esempio n. 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class with the desired options.
 /// </summary>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(PhantomJSOptions options)
     : this(PhantomJSDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(60))
 {
 }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified path
 /// to the directory containing PhantomJS.exe and options.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, PhantomJSOptions options)
     : this(phantomJSDriverServerDirectory, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Returns an initialised PhantomJS Web Driver.
 /// </summary>
 /// <remarks>You need to have phantomjs.exe embedded into your assembly</remarks>
 /// <param name="options">Options to configure the driver</param>
 /// <returns>Initialised PhantomJS driver</returns>
 public static PhantomJSDriver PhantomJS(PhantomJSOptions options)
 {
     return new WebDriverBuilder<PhantomJSDriver>(() => new PhantomJSDriver(options))
         .WithFileName("phantomjs.exe");
 }
Esempio n. 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified <see cref="PhantomJSDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout, false), ConvertOptionsToCapabilities(options))
 {
     // Add the custom commandInfo of PhantomJSDriver
     CommandInfo commandInfo = new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/phantom/execute");
     this.CommandExecutor.CommandInfoRepository.TryAddCommand(CommandExecutePhantomScript, commandInfo);
 }
Esempio n. 22
0
 public PhantomJsBrowserDriver(string phantomJsServerPath,PhantomJSOptions options)
 {
     mBrowserFactory=()=>new PhantomJSDriver(phantomJsServerPath,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);
        }
Esempio n. 24
0
        public IWebDriver Create()
        {
            IWebDriver driver;
            Func<string, string, string> c = (x,y) => x.Replace(x,y);
            var currentDay = "Friday";
            var horribleDay = "Monday";
            var differentDay = c(currentDay, "horribleDay");
            var driverToUse = ConfigurationHelper.Get<DriverToUse>("DriverToUse");
            var useGrid = ConfigurationHelper.Get<bool>("UseGrid");
            if (useGrid)
            {
                driver = CreateGridDriver(driverToUse);
            }
            else
            {

                switch (driverToUse)
                {
                    case DriverToUse.InternetExplorer:
                        driver = new InternetExplorerDriver(AppDomain.CurrentDomain.BaseDirectory, new InternetExplorerOptions(), TimeSpan.FromMinutes(5));
                        break;
                    case DriverToUse.Firefox:
                        var firefoxProfile = FirefoxProfile;
                        driver = new FirefoxDriver(firefoxProfile);
                        driver.Manage().Window.Maximize();
                        break;
                    case DriverToUse.Chrome:
                        driver = new ChromeDriver();
                        break;
                    case DriverToUse.PhantomJS:
                        driver = new PhantomJSDriver();
                        PhantomJSOptions o = new PhantomJSOptions();

                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            driver.Manage().Window.Maximize();
            var timeouts = driver.Manage().Timeouts();

            timeouts.ImplicitlyWait(TimeSpan.FromSeconds(ConfigurationHelper.Get<int>("ImplicitlyWait")));
            timeouts.SetPageLoadTimeout(TimeSpan.FromSeconds(ConfigurationHelper.Get<int>("PageLoadTimeout")));

            // Suppress the onbeforeunload event first. This prevents the application hanging on a dialog box that does not close.
            //((IJavaScriptExecutor)driver).ExecuteScript("window.onbeforeunload = function(e){};");
            return driver;
        }
        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);
        }
        public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout) : base(new DriverServiceCommandExecutor(service, commandTimeout, false), PhantomJSDriver.ConvertOptionsToCapabilities(options))
        {
            CommandInfo commandInfo = new CommandInfo("POST", "/session/{sessionId}/phantom/execute");

            base.CommandExecutor.CommandInfoRepository.TryAddCommand("executePhantomScript", commandInfo);
        }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified path
 /// to the directory containing PhantomJS.exe, options, and command timeout.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, PhantomJSOptions options, TimeSpan commandTimeout)
     : this(PhantomJSDriverService.CreateDefaultService(phantomJSDriverServerDirectory), options, commandTimeout)
 {
 }
Esempio n. 28
0
 /// <summary>
 /// Returns an initialised PhantomJS Web Driver.
 /// </summary>
 /// <remarks>You need to have phantomjs.exe embedded into your assembly</remarks>
 /// <param name="options">Options to configure the driver</param>
 /// <returns>Initialised PhantomJS driver</returns>
 public static PhantomJSDriver PhantomJS(PhantomJSOptions options)
 {
     CreateDriver("phantomjs.exe");
     return new PhantomJSDriver(options);
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified
 /// <see cref="PhantomJSDriverService"/> and options.
 /// </summary>
 /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options)
     : this(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
Esempio n. 30
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;
        }
Esempio n. 31
0
        private static ICapabilities ConvertOptionsToCapabilities(PhantomJSOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "options must not be null");
            }

            return options.ToCapabilities();
        }
Esempio n. 32
0
 private static PhantomJSOptions GetPhantomJsOptions()
 {
     PhantomJSOptions option = new PhantomJSOptions();
     option.AddAdditionalCapability("handlesAlerts", true);
     return option;
 }
 /// <summary>
 /// Initializes a new instance of the PhantomJSDriver class using the specified <see cref="PhantomJSDriverService"/>.
 /// </summary>
 /// <param name="service">The <see cref="PhantomJSDriverService"/> to use.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public PhantomJSDriver(PhantomJSDriverService service, PhantomJSOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout, false), options.ToCapabilities())
 {
 }
Esempio n. 34
0
 /// <summary>
 /// Initializes a new instance of the PhantomJSDriver class using the specified path to the directory containing IEDriverServer.exe and command timeout.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="ghostDriverMainDirectory">The full path to the directory containing the GhostDriver JavaScript library's main.js file.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, string ghostDriverMainDirectory, PhantomJSOptions options)
     : this(phantomJSDriverServerDirectory, ghostDriverMainDirectory, options, TimeSpan.FromSeconds(60))
 {
 }
Esempio n. 35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class using the specified path
 /// to the directory containing PhantomJS.exe, options, and command timeout.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, PhantomJSOptions options, TimeSpan commandTimeout)
     : this(PhantomJSDriverService.CreateDefaultService(phantomJSDriverServerDirectory), options, commandTimeout)
 {
 }
 private static PhantomJSOptions GetPhantomJsptions()
 {
     var option = new PhantomJSOptions();
     option.AddAdditionalCapability("handlesAlerts", true);
     Logger.Info("Using PhantomJSOptions");
     return option;
 }
Esempio n. 37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PhantomJSDriver"/> class with the desired options.
 /// </summary>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(PhantomJSOptions options)
     : this(PhantomJSDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(60))
 {
 }
Esempio n. 38
0
 /// <summary>
 /// Initializes a new instance of the PhantomJSDriver class using the specified path to the directory containing IEDriverServer.exe and command timeout.
 /// </summary>
 /// <param name="phantomJSDriverServerDirectory">The full path to the directory containing PhantomJS.exe.</param>
 /// <param name="ghostDriverMainDirectory">The full path to the directory containing the GhostDriver JavaScript library's main.js file.</param>
 /// <param name="options">The <see cref="PhantomJSOptions"/> used to initialize the driver.</param>
 public PhantomJSDriver(string phantomJSDriverServerDirectory, string ghostDriverMainDirectory, PhantomJSOptions options)
     : this(phantomJSDriverServerDirectory, ghostDriverMainDirectory, options, TimeSpan.FromSeconds(60))
 {
 }
Esempio n. 39
-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();
                }
            }
        }