public void CanLoadWebPageTest() { // add the directory containing chromedriver.exe to PATH var driver = new ChromeDriver(); var baseURL = "http://localhost:6917/"; try { driver.Navigate().GoToUrl(baseURL + "/"); driver.FindElement(By.Id("Name")).Clear(); driver.FindElement(By.Id("Name")).SendKeys("Test"); new SelectElement(driver.FindElement(By.Id("Color"))).SelectByText("Red"); driver.FindElement(By.CssSelector("option[value=\"Red\"]")).Click(); driver.FindElement(By.CssSelector("input.btn")).Click(); var element = driver.FindElement(By.Name("PreviousNames[0].FirstName"), 3); element.Clear(); driver.FindElement(By.Name("PreviousNames[0].FirstName")).SendKeys("ONe"); driver.FindElement(By.Name("PreviousNames[0].Surname")).Clear(); driver.FindElement(By.Name("PreviousNames[0].Surname")).SendKeys("Two"); var screenshot = driver.GetScreenshot(); screenshot.SaveAsFile("screenshot.png", ImageFormat.Png); driver.FindElement(By.CssSelector("input.btn.btn-success")).Click(); } catch (Exception) { Screenshot screenshot = driver.GetScreenshot(); screenshot.SaveAsFile("screenshot-error.png", ImageFormat.Png); throw; } driver.Quit(); }
public void snapshot(TestStep ts) { try { string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"; ch.GetScreenshot().SaveAsFile(resultPath + fileName, System.Drawing.Imaging.ImageFormat.Jpeg); ts.Step.SetAttributeValue("Photo", fileName); } catch { } }
public void BrowserTEst() { var drive2r = new ChromeDriver(@"d:\temp\"); // Initialize the Chrome Driver using (var driver = new ChromeDriver(@"d:\temp\")) { // Go to the home page driver.Navigate().GoToUrl("http://www.hkticketing.com/"); driver.FindElement(By.LinkText("Login/Register")).Click(); driver.FindElement(By.Id("email")).Clear(); driver.FindElement(By.Id("email")).SendKeys("*****@*****.**"); driver.FindElement(By.Id("login")).Click(); driver.FindElement(By.Id("uniform-login")).Click(); driver.FindElement(By.Id("pw")).Clear(); driver.FindElement(By.Id("pw")).SendKeys("xxxxx"); driver.FindElement(By.Id("login")).Click(); driver.Navigate().GoToUrl("https://www2.hkticketing.com/HKTWebApp/Booking.do?contentCode=MCCHEER0716&language=en_US"); // Get the page elements var userNameField = driver.FindElementById("usr"); var userPasswordField = driver.FindElementById("pwd"); // Take a screenshot and save it into screen.png driver.GetScreenshot().SaveAsFile(@"d:\temp\screen.png", ImageFormat.Png); } }