Skip to content

Commit

Permalink
Selenate/upgrade selenium 4 (#129)
Browse files Browse the repository at this point in the history
* Upgrade to selenium 4

* Facilitate chaining FindElement and FindElements calls
  • Loading branch information
PandaMagnus authored Oct 7, 2022
1 parent 58b9d25 commit 02d51df
Show file tree
Hide file tree
Showing 24 changed files with 1,210 additions and 1,004 deletions.
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
using OpenQA.Selenium;
using System;
using Xunit;
namespace IntelliTect.TestTools.Selenate.Examples;

namespace IntelliTect.TestTools.Selenate.Examples
public class BasicDriverInteractions : TestBase
{
public class BasicDriverInteractions : TestBase
[Fact]
public void NavigateAndGetWindowTitle()
{
[Fact]
public void NavigateAndGetWindowTitle()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/");
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/");

Assert.Equal("The Internet", DriverHandler.GetWindowTitle());
}

[Fact]
public void Click()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/")
.FindElement(By.CssSelector("a[href='/abtest']"))
.Click();

Assert.Equal("A/B Test Control", DriverHandler.FindElement(By.CssSelector("div[class='example']>h3"))
.Text());
}

[Fact]
public void FindAlert()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/javascript_alerts")
.FindElement(By.CssSelector("button[onclick='jsConfirm()']"))
.Click();

DriverHandler.SwitchToAlert().Accept();
Assert.Equal("The Internet", DriverHandler.GetWindowTitle());
}

Assert.Equal(
"You clicked: Ok",
DriverHandler.FindElement(By.CssSelector("p[id='result']")).Text());
}
[Fact]
public void FindAlert()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/javascript_alerts")
.FindElement(By.CssSelector("button[onclick='jsConfirm()']"))
.Click();

[Fact]
public void FindWindow()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/windows")
.FindElement(By.CssSelector("a[href='/windows/new']"))
.Click();
DriverHandler.SwitchToAlert().Accept();

// If the window is not found, this will throw
Assert.Equal("New Window",
DriverHandler
.SwitchToWindow("New Window")
.GetWindowTitle());
}
Assert.Equal(
"You clicked: Ok",
DriverHandler.FindElement(By.CssSelector("p[id='result']")).Text());
}

[Fact]
public void FindFrame()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/nested_frames");
[Fact]
public void FindWindow()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/windows")
.FindElement(By.CssSelector("a[href='/windows/new']"))
.Click();

// If the window is not found, this will throw
Assert.Equal("New Window",
DriverHandler
.SwitchToWindow("New Window")
.GetWindowTitle());
}

Assert.Equal("LEFT",
DriverHandler.SwitchToIFrame(
By.CssSelector("frame[src='/frame_top']"),
By.CssSelector("frame[src='/frame_left']"))
.FindElement(By.CssSelector("body"))
.Text());
}
[Fact]
public void FindFrame()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/nested_frames");

Assert.Equal("LEFT",
DriverHandler.SwitchToIFrame(
By.CssSelector("frame[src='/frame_top']"),
By.CssSelector("frame[src='/frame_left']"))
.FindElement(By.CssSelector("body"))
.Text());
}
}
Original file line number Diff line number Diff line change
@@ -1,92 +1,102 @@
using IntelliTect.TestTools.Selenate.Examples.Pages;
using Xunit;
namespace IntelliTect.TestTools.Selenate.Examples;

namespace IntelliTect.TestTools.Selenate.Examples
public class BasicElementInteractions : TestBase
{
public class BasicElementInteractions : TestBase
public BasicElementInteractions()
{
public BasicElementInteractions()
{
_DynamicLoadingPage = new DynamicLoadingPages(WebDriver);
_DynamicControlsPage = new DynamicControlsPage(WebDriver);
_DropDownPage = new DropDownPage(WebDriver);
}

private readonly DynamicLoadingPages _DynamicLoadingPage;
private readonly DynamicControlsPage _DynamicControlsPage;
private readonly DropDownPage _DropDownPage;


// Below two tests should functionally operate the same
[Fact]
public void FindElementThatIsUnhiddenAfterPageLoad()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_loading/1");

_DynamicLoadingPage.StartButton.Click();

Assert.True(
_DynamicLoadingPage.HelloWorldLabel
.SetTimeoutSeconds(8)
.WaitForDisplayed(),
"Hello World label did not appear when we expected it to.");
}

[Fact]
public void ClearAndSendKeys()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");
_DynamicControlsPage.EnableDisableButton.Click();
_DynamicControlsPage.TextBox.SendKeys("Hello!");
Assert.Equal("Hello!", _DynamicControlsPage.TextBox.GetAttribute("value"));
_DynamicControlsPage.TextBox.Clear();
Assert.Equal("", _DynamicControlsPage.TextBox.GetAttribute("value"));
}

[Fact]
public void FindElementThatIsCreatedAfterPageLoad()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_loading/2");

_DynamicLoadingPage.StartButton.Click();

Assert.True(
_DynamicLoadingPage.HelloWorldLabel
.SetTimeoutSeconds(8)
.WaitForDisplayed(),
"Hello World label did not appear when we expected it to.");
}

[Fact]
public void CheckForVisibleStates()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");

Assert.True(_DynamicControlsPage.Checkbox.WaitForDisplayed());
_DynamicControlsPage.RemoveAddButton.Click();
Assert.True(_DynamicControlsPage.Checkbox.WaitForNotDisplayed());
_DynamicControlsPage.RemoveAddButton.Click();
Assert.True(_DynamicControlsPage.Checkbox.WaitForDisplayed());
}

[Fact]
public void CheckForElementEnabledStates()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");

Assert.True(_DynamicControlsPage.TextBox.WaitForDisabled());
_DynamicControlsPage.EnableDisableButton.Click();
Assert.True(_DynamicControlsPage.TextBox.WaitForEnabled());
_DynamicControlsPage.EnableDisableButton.Click();
Assert.True(_DynamicControlsPage.TextBox.WaitForDisabled());
}

[Fact]
public void ManipulateSelectElement()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dropdown");
_DropDownPage.DropDownSelect.SelectByText("Option 2");
Assert.Equal("Option 2", _DropDownPage.DropDownSelect.SelectedOption.Text);
}
_DynamicLoadingPage = new DynamicLoadingPages(WebDriver);
_DynamicControlsPage = new DynamicControlsPage(WebDriver);
_DropDownPage = new DropDownPage(WebDriver);
_ShadowDomPage = new ShadowDomPage(WebDriver);
}

private readonly DynamicLoadingPages _DynamicLoadingPage;
private readonly DynamicControlsPage _DynamicControlsPage;
private readonly DropDownPage _DropDownPage;
private readonly ShadowDomPage _ShadowDomPage;


// Below two tests should functionally operate the same
[Fact]
public void FindElementThatIsUnhiddenAfterPageLoad()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_loading/1");

_DynamicLoadingPage.StartButton.GetWebElement().FindElements(OpenQA.Selenium.By.Id("testing"));

_DynamicLoadingPage.StartButton.Click();

Assert.True(
_DynamicLoadingPage.HelloWorldLabel
.SetTimeoutSeconds(8)
.WaitForDisplayed(),
"Hello World label did not appear when we expected it to.");
}

[Fact]
public void ClearAndSendKeys()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");
_DynamicControlsPage.EnableDisableButton.Click();
_DynamicControlsPage.TextBox.SendKeys("Hello!");
Assert.Equal("Hello!", _DynamicControlsPage.TextBox.GetAttribute("value"));
_DynamicControlsPage.TextBox.Clear();
Assert.Equal("", _DynamicControlsPage.TextBox.GetAttribute("value"));
}

[Fact]
public void FindElementThatIsCreatedAfterPageLoad()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_loading/2");

_DynamicLoadingPage.StartButton.Click();

Assert.True(
_DynamicLoadingPage.HelloWorldLabel
.SetTimeoutSeconds(8)
.WaitForDisplayed(),
"Hello World label did not appear when we expected it to.");
}

[Fact]
public void CheckForVisibleStates()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");

Assert.True(_DynamicControlsPage.Checkbox.WaitForDisplayed());
_DynamicControlsPage.RemoveAddButton.Click();
Assert.True(_DynamicControlsPage.Checkbox.WaitForNotDisplayed());
_DynamicControlsPage.RemoveAddButton.Click();
Assert.True(_DynamicControlsPage.Checkbox.WaitForDisplayed());
}

[Fact]
public void CheckForElementEnabledStates()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dynamic_controls");

Assert.True(_DynamicControlsPage.TextBox.WaitForDisabled());
_DynamicControlsPage.EnableDisableButton.Click();
Assert.True(_DynamicControlsPage.TextBox.WaitForEnabled());
_DynamicControlsPage.EnableDisableButton.Click();
Assert.True(_DynamicControlsPage.TextBox.WaitForDisabled());
}

[Fact]
public void ManipulateSelectElement()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/dropdown");
_DropDownPage.DropDownSelect.SelectByText("Option 2");
Assert.Equal("Option 2", _DropDownPage.DropDownSelect.SelectedOption.Text);
}

[Fact]
public void FindElementsInShadowDom()
{
DriverHandler.NavigateToPage("https://the-internet.herokuapp.com/shadowdom");
string originalText = _ShadowDomPage.OriginalText.Text();
string displayedText = _ShadowDomPage.DisplayedText.Text();
Assert.Equal("My default text", originalText);
Assert.Equal("Let's have some different text!", displayedText);
}
}
Loading

0 comments on commit 02d51df

Please sign in to comment.