| // This could be compressed down to a one-line piece of code like this: | |
| // IWebElement error_Site_AppServerError => new WebDriverWait(DriverInstance.Driver, TimeSpan.FromSeconds(5)).Until((d) => d.FindElement(By.XPath("//*[@id='header']/h1[contains(text(),'Server Error')]")); | |
| // But as one can see, that makes for code that's difficult to read, maintain, and see the intention of. | |
| IWebElement error_Site_AppServerError | |
| { | |
| get | |
| { | |
| WebDriverWait wait = new WebDriverWait(DriverInstance.Driver, TimeSpan.FromSeconds(5)); | |
| return wait.Until((d) => d.FindElement(By.XPath("//*[@id='header']/h1[contains(text(),'Server Error')]")); | |
| } | |
| } | |
| IWebElement IMG_Logo_Tenant => DriverInstance.Driver.FindElement(By.XPath("//*[@id='tenant-logo']/img")); | |
| [Test] | |
| public void test1() | |
| { | |
| try | |
| { | |
| OpenBrowser("chrom"); | |
| NavigateToSite("https://mysite123.com"); | |
| Console.WriteLine("Helloooooo"); | |
| Assert.That(IMG_Logo_Tenant.Displayed, Is.True); | |
| Assert.IsTrue(ElementHelper.IsElementDisplayed(IMG_Logo_Tenant)); | |
| Assert.IsFalse(ElementHelper.IsElementDisplayed(error_Site_AppServerError)); | |
| } | |
| catch(Exception e) | |
| { | |
| cw(e.message); | |
| } | |
| } | |
| // IsElement Display Function | |
| public static bool IsElementDisplayed(IWebElement element) | |
| { | |
| try | |
| { | |
| bool ele = element.Displayed; | |
| return true; | |
| } | |
| catch (Exception) // Tried NosuchElementException as well in actch block but still directly throwing error for line 4. | |
| { | |
| return false; | |
| throw new Exception(string.Format("Element Not Displayed or Enabled Exception")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment