Example #1
0
 public void TestInitialize()
 {
     Contexts.Clear();
     ClientTests.Clear();
     Server = new ServerFixture();
     BrowserFixtures.Clear();
     BrowserFixtures.Add(new BrowserFixture());
     ScreenshotCapture = new ScreenshotCapture();
 }
Example #2
0
    public void takeScreenShot()
    {
        isScreenShotSaved      = false;
        isScreenShotSaveFailed = false;

        // Capture
        StartCoroutine(ScreenshotCapture.Capture(
                           Const.SC_NAME,
                           callbackCapture)
                       );
    }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Taking screenshot... OS : {0} ", Environment.OSVersion.Platform);

            using (var screen = ScreenshotCapture.TakeScreenshot())
            {
                screen.Save(Path.Combine(Environment.CurrentDirectory, "Screenshot.jpg"), ImageFormat.Jpeg);
            }
            Console.WriteLine("Done");
            Console.ReadLine();
        }
Example #4
0
    public void capture()
    {
        counter++;
        string str = "Capture Count\n" + counter;

        _label.text = str;

        // Capture
        StartCoroutine(ScreenshotCapture.Capture(
                           fileName,
                           callbackCapture)
                       );

        _wall.SetActive(true);
    }
Example #5
0
        private TrackerPayload GetTrackerPayload()
        {
            var world   = "./images/world.jpg";
            var tracker = new Tracker();

            using (var minimap = new TempFile("jpeg"))
                using (var screencapturer = new ScreenshotCapture())
                {
                    screencapturer.TakeScreenshot(minimap.Path);
                    var coord = tracker.Match(minimap.Path, world);

                    return(new TrackerPayload()
                    {
                        Coord = coord
                    });
                }
        }
Example #6
0
        private async void Window_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_dragging)
            {
                var end       = e.GetPosition(this);
                var selection = GetSelection(end);

                if (!selection.IsEmpty)
                {
                    // Hide overlay before capturing screenshot
                    Hide();
                    await Task.Delay(TimeSpan.FromMilliseconds(100));

                    // Capture screenshot of selected region
                    var original = new Bitmap(ScreenshotCapture.TakeScreenshot())
                                   .Crop(selection)
                                   .CropToContent();

                    // Invert colors of screenshot if needed to ensure good OCR result
                    var modified = original.Scale(2);
                    if (modified.IsDark(50))
                    {
                        modified = modified.InvertColors();
                    }

                    var text = modified.ToBlackAndWhite().Ocr().Item1;
                    var pair = new BitmapTextPair(
                        original.ToImageSource(),
                        modified.ToImageSource(),
                        text
                        );

                    // Launch snippet manager
                    _ocrSnippetWindow.Model.BitmapPairs.Add(pair);
                    _ocrSnippetWindow.Show();

                    Close();
                    return;
                }
            }

            _dragging  = false;
            _startDrag = default;
            e.Handled  = true;
        }
Example #7
0
        public void TestCleanup()
        {
            ScreenshotCapture = null;
            ClientTests.Clear();
            Contexts.Clear();

            foreach (var browserFixture in BrowserFixtures)
            {
                browserFixture.Dispose();
            }

            BrowserFixtures.Clear();

            if (Server != null)
            {
                Server.Dispose();
                Server = null;
            }
        }
Example #8
0
        public void TestFinished(TestResult result)
        {
            try
            {
                if (!result.IsSuccess && result.ResultState != ResultState.Ignored && result.ResultState != ResultState.Skipped && result.ResultState != ResultState.NotRunnable)
                {
                    Debug.Print(string.Format("{0}\n{1}", result.Message, result.StackTrace));

                    // Try to get screenshots of application
                    var dirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Screenshots";
                    Directory.CreateDirectory(dirPath);
                    var fileName = Path.GetInvalidFileNameChars().Aggregate(result.Test.TestName.Name, (current, c) => current.Replace(c.ToString(CultureInfo.InvariantCulture), string.Empty));

                    if (dirPath.Length > 249)
                    {
                        Debug.Print("Directory path is very long!");
                        throw new Exception("Directory path is very long!");
                    }

                    if (dirPath.Length + fileName.Length >= 249)
                    {
                        fileName = fileName.Substring(0, 249 - dirPath.Length);
                    }

                    Debug.Print(string.Format("Taking screenshot: {0}\\{1}", dirPath, fileName));
                    try
                    {
                        ScreenshotCapture.TakeScreenshot(true).Save(string.Format("{0}\\{1}_Full.png", dirPath, fileName), ImageFormat.Png);
                    }
                    catch (Exception exp)
                    {
                    }
                }

                Debug.Print(string.Format("Test Result : {0} and Test Name : {1}", result.ResultState, result.Name));
                Application.Close();
            }
            catch (Exception exp)
            {
                Debug.Print(exp.Message, exp);
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            //var minimap = "./images/minimap_org.jpg";
            var world   = "./images/world.jpg";
            var tracker = new Tracker();

            using (var minimap = new TempFile("jpeg"))
                using (var screencapturer = new ScreenshotCapture())
                {
                    screencapturer.TakeScreenshot(minimap.Path);
                    var coord = tracker.Match(minimap.Path, world);
                }

            //var minimaps = Directory.EnumerateFiles("./screenshots/", "*.png");

            //foreach (var minimap in minimaps)
            //{
            //    tracker.Match(minimap, world);
            //}
        }
Example #10
0
        public void SetUpDriver()
        {
            switch (TestConfigurations.browserName)
            {
            case "firefox":
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.AddArguments("--start-maximized");
                WebDriverFromBaseClass = new FirefoxDriver(firefoxOptions);
                break;

            case "chrome":
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
                chromeOptions.AddArguments("--start-maximized");
                WebDriverFromBaseClass = new ChromeDriver(chromeOptions);
                break;

            case "ie":
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                //ieOptions.AddArguments("--start-maximized");
                //IEDriverServer.exe
                WebDriverFromBaseClass = new InternetExplorerDriver();
                break;

            case "edge":
                WebDriverFromBaseClass = new EdgeDriver();
                //EdgeOptions edOptions = new EdgeOptions();
                //edOptions.AddAdditionalCapability("--start-maximized", true);
                //WebDriverFromBaseClass = new EdgeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), edOptions);
                break;

            default:
                Console.WriteLine("Improper Browser Name Keyed in");
                break;
            }
            WebDriverFromBaseClass.Navigate().GoToUrl(TestConfigurations.baseUrl);
            aClass   = new AssertClass(WebDriverFromBaseClass);
            sCapture = new ScreenshotCapture(WebDriverFromBaseClass);
        }
Example #11
0
 public Bitmap TakeScreenshot()
 {
     return(new Bitmap(ScreenshotCapture.TakeScreenshot()));
 }