Пример #1
0
        /// <summary>
        /// Takes a screenshot of the given WebDriver's current page.
        /// </summary>
        /// <returns>The string of the file path for the screenshot taken.</returns>
        public static string TakeScreenshot()
        {
            // Declare an empty object to hold the return value
            string returnValue = null;

            // Log Before Action
            Log.BeforeAction();

            // Perform the action
            try
            {
                // Get the screenshot folder, set in TestBase.Setup() using App.config value
                string screenshotFolder = Context.Get("screenshotFolder").ToString();
                // Create directory (if it does not exist)
                string date      = DateUtilities.GetCurrentDate();
                string directory = screenshotFolder + date;
                if (screenshotFolder.Contains("/"))
                {
                    directory = directory + "/";
                }
                else
                {
                    directory = directory + "\\";
                }
                // Create a sub-directory using today's date
                Directory.CreateDirectory(directory);
                // Build a file name (*NOTE: The folder must already exist and allow writes to it)
                string time = DateUtilities.GetCurrentTime();
                returnValue = directory + time + ".jpg";
                // Take a screenshot
                Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();
                screenshot.SaveAsFile(returnValue, ScreenshotImageFormat.Jpeg);
                // Logging - After action success
                Log.Success("File Name: " + returnValue);
            }
            catch (Exception e)
            {
                // Logging - After action exception
                Log.Failure(e.Message);
                // Fail current test
                //Assert.Fail(e.Message); // Do not fail the test if a screenshot can not be saved
            }
            finally
            {
                // Logging - After action
                Log.Finally();
            }
            // Return the filename of the screenshot
            return(returnValue);
        }
Пример #2
0
        private async Task StartScannerAsync()
        {
            if (scannerIsActive)
            {
                return;
            }

            scannerIsActive = true;

            _ = Task.Run(async() => {
                await OnLogAsync(LogSeverity.Info, "Starting trophy scanner");

                while (queue.Count > 0)
                {
                    // Wait until the next item in the queue has been sitting for at least SCAN_DELAY.

                    DateTimeOffset currentDate = DateUtilities.GetCurrentDate();
                    DateTimeOffset itemDate    = queue.First().DateAdded;

                    if ((currentDate - itemDate).TotalSeconds < ScanDelay)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(ScanDelay - (currentDate - itemDate).TotalSeconds));
                    }

                    // Scan trophies for the next item in the queue.

                    if (queue.TryDequeue(out QueueItem item))
                    {
                        await ScanTrophiesAsync(item);
                    }
                }

                // When we've processed all users in the queue, shut down the scanner.

                scannerIsActive = false;

                await OnLogAsync(LogSeverity.Info, "Shutting down trophy scanner");
            });

            await Task.CompletedTask;
        }
Пример #3
0
        public int ScanDelay => 60 * 5; // 5 minutes

        public async Task <bool> EnqueueAsync(ITrophyScannerContext context, bool scanImmediately = false)
        {
            // If the user already exists in the queue, don't add them again.

            if (context.Creator.UserId.HasValue && !queue.Any(item => item.Context.Creator.UserId == context.Creator.UserId))
            {
                // Add the user to the scanner queue.

                queue.Enqueue(new QueueItem {
                    Context   = context,
                    DateAdded = scanImmediately ? DateTimeOffset.MinValue : DateUtilities.GetCurrentDate()
                });

                // Since there's something in the queue, start the trophy scanner (nothing will happen if it's already active).

                await StartScannerAsync();

                return(true);
            }

            return(false);
        }