Ejemplo n.º 1
0
        public void AfterMethod()
        {
            // inc. class name
            var fullNameOfTheMethod = NUnit.Framework.TestContext.CurrentContext.Test.FullName;

            Console.WriteLine("===========>" + fullNameOfTheMethod);//C_Sharp_Selenium_NUnit.Test_Cases.TearDown_ScreenShot.TestMethod

            // method name only
            var methodName = NUnit.Framework.TestContext.CurrentContext.Test.Name;

            Console.WriteLine("===========>" + methodName); //TestMethod

            // the state of the test execution
            var state = NUnit.Framework.TestContext.CurrentContext.Result.Outcome; // TestState enum

            Console.WriteLine("===========>" + state.ToString());                  // 1. (Failed:Error) 2. (Passed)

            if (!(state.ToString() == "Passed"))
            {
                OpenQA.Selenium.ITakesScreenshot ts = driver as ITakesScreenshot;
                Screenshot screenshot = ts.GetScreenshot();
                screenshot.SaveAsFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..")) + "\\Screenshot\\" + methodName + ".png", ScreenshotImageFormat.Png);
            }

            Thread.Sleep(3000);
            driver.Close();
            driver.Quit();
        }
Ejemplo n.º 2
0
        public void demo()
        {
            driver.Url = "https://www.google.com";
            OpenQA.Selenium.ITakesScreenshot ts = driver as ITakesScreenshot;
            Screenshot screenshot = ts.GetScreenshot();

            screenshot.SaveAsFile(Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..")) + "\\Screenshot\\" + "TestScreensot" + ".png", ScreenshotImageFormat.Png);
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            int milliseconds_in_second = 1000;

/*
 *          var options = new OpenQA.Selenium.Chrome.ChromeOptions();
 *          //options.BinaryLocation = "/usr/share/iron/chrome-wrapper";
 *          options.BinaryLocation = "/wd/hub";
 *          options.DebuggerAddress  = "localhost:4444";
 *          options.
 *
 * driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
 *          System.setProperty("webdriver.chrome.driver","");
 *
 *
 *                      using (var driver = new ChromeDriver("/media/jhaines/tera27/file-set/workspace/coffeebreak-test/bin/Debug/netcoreapp2.1/", options))
 */


            // Initialize the Chrome Driver
            //using (var driver = new ChromeDriver("/media/jhaines/tera27/file-set/workspace/coffeebreak-test/bin/Debug/netcoreapp2.1/", options))
            using (var driver = get_remote_chrome_driver())
            {
                findByXPath      = driver as OpenQA.Selenium.Internal.IFindsByXPath;
                ITakesScreenshot = driver as OpenQA.Selenium.ITakesScreenshot;
                // Go to the home page
                driver.Navigate().GoToUrl(app_url);

                System.Threading.Thread.Sleep(1 * milliseconds_in_second);

/*
 *              // Get the page elements
 *              var login_toggle = driver.FindElementByXPath("//li[@id='profile_content_id']/a");
 *              login_toggle.Click();
 *              var userNameField = driver.FindElementByXPath("//*[@id='profile_content_id2']/div/input[1]");
 *              var userPasswordField = driver.FindElementByXPath("//*[@id='profile_content_id2']/div/input[2]");
 *              var loginButton = driver.FindElementByXPath("//*[@id='profile_content_id2']/div/input[3]");
 *              // Type user name and password
 *              userNameField.SendKeys("user1");
 *              userPasswordField.SendKeys("password");
 *              // and click the login button
 *              loginButton.Click();
 */
                set_value("/html/body/form/input[1]", "user1", "user_name");
                set_value("/html/body/form/input[2]", "password", "password");
                click("/html/body/form/input[3]", "login_click");


/*
 *              // Extract the text and save it into result.txt
 *              var result = driver.FindElementById("form_content_id").Text;
 *              File.WriteAllText("result.txt", result);
 *
 *              // Take a screenshot and save it into screen.png
 *              driver.GetScreenshot().SaveAsFile(@"screen.png", ScreenshotImageFormat.Png);
 *
 *              System.Threading.Thread.Sleep(5 * milliseconds_in_second);
 *
 *
 *              var AddNewCaseButton = driver.FindElementByXPath("//*[@id='app_summary']/input[1]");
 *              AddNewCaseButton.Click();
 */
                System.Threading.Thread.Sleep(5 * milliseconds_in_second);
                // Take a screenshot and save it into screen.png
                TakeScreenshot(@"add_new_case.png");

                Assert.Equal(1, 1);
            }
        }