using System; using System.IO; using System.Threading; using NUnit.Framework; using NUnit.Framework.Interfaces; using OpenQA.Selenium; using OpenQA.Selenium.Edge; using OpenQA.Selenium.Support.UI; using SeleniumExtras.WaitHelpers; namespace basic { public class Tests { private static IWebDriver Driver; private static WebDriverWait wait; [SetUp] public void Setup() { EdgeOptions? options = new EdgeOptions(); options.AddArguments("--headless"); Driver = new EdgeDriver(options); wait = new WebDriverWait(Driver, System.TimeSpan.FromSeconds(60)); Driver.Manage().Window.Maximize(); Driver.Navigate().GoToUrl("https://outlook.office.com"); } [Test] public void ClickNewMessage() { Thread.Sleep(10000); if (Driver.FindElements(UseAccount).Count > 0) { Driver.FindElement(UseAccount).Click(); } wait.Until(ExpectedConditions.ElementToBeClickable(this.UserName)); this.UserName.SendKeys("Account@.onmicrosoft.com"); wait.Until(ExpectedConditions.ElementToBeClickable(NextButton)).Click(); Thread.Sleep(10000); Thread.Sleep(10000); Password.SendKeys("PAsswo"); Thread.Sleep(10000); wait.Until(ExpectedConditions.ElementToBeClickable(LoginButton)).Click(); Thread.Sleep(10000); wait.Until(ExpectedConditions.ElementToBeClickable(YesButton)).Click(); wait.Until(ExpectedConditions.ElementToBeClickable(NewMessage)).Click(); } public IWebElement UserName => Driver.FindElement(By.XPath("//input[@type='email']")); public IWebElement Password => Driver.FindElement(By.XPath("//input[@name='passwd']")); public IWebElement NextButton => Driver.FindElement(By.XPath("//input[@value='Next']")); public IWebElement YesButton => Driver.FindElement(By.XPath("//input[@value='Yes']")); public IWebElement LoginButton => Driver.FindElement(By.XPath("//input[@value='Sign in']")); public By UseAccount => By.CssSelector("div#otherTile img"); public By NewMessage => By.XPath("//span[text()='New message']"); [TearDown] public void TearDown() { TestStatus status = TestContext.CurrentContext.Result.Outcome.Status; if (status == TestStatus.Failed) { SaveScreenShot(TestContext.CurrentContext.Test.Name + DateTime.Now.ToString("dd-MM-t-mm-ss")); } } public void SaveScreenShot(String Name) { ITakesScreenshot ts = (ITakesScreenshot)Driver; Screenshot screenshot = ts.GetScreenshot(); string path = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\ScreenShot"; string finalpath = @$"{path}\{Name}.png"; string localpath = new Uri(finalpath).LocalPath; screenshot.SaveAsFile(localpath); } } }