Skip to content

Instantly share code, notes, and snippets.

@nakov
Created January 24, 2021 12:08
Show Gist options
  • Save nakov/a2d65c857ba6e4502f1467022b598752 to your computer and use it in GitHub Desktop.
Save nakov/a2d65c857ba6e4502f1467022b598752 to your computer and use it in GitHub Desktop.
Selenium XE.com automation: convert 1 EUR to BGN and assert the rate is correct
[Test]
public void Test_XECom_EurBgnCourse_ByKeyboard()
{
driver.Navigate().GoToUrl("https://xe.com");
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
// Choose amount "1"
driver.FindElement(By.CssSelector("input#amount")).Click();
driver.FindElement(By.CssSelector("input#amount")).SendKeys("1");
// Choose source currency "EUR"
driver.SwitchTo().ActiveElement().SendKeys(Keys.Tab);
driver.SwitchTo().ActiveElement().SendKeys("eur");
driver.SwitchTo().ActiveElement().SendKeys(Keys.Enter);
// Choose destination currency "BGN"
driver.SwitchTo().ActiveElement().SendKeys(Keys.Tab);
driver.SwitchTo().ActiveElement().SendKeys(Keys.Tab);
driver.SwitchTo().ActiveElement().SendKeys("bgn");
driver.SwitchTo().ActiveElement().SendKeys(Keys.Enter);
// Click the [Submit] button
driver.SwitchTo().ActiveElement().SendKeys(Keys.Tab);
driver.SwitchTo().ActiveElement().SendKeys(Keys.Enter);
// Assert the conversion rate is correct
var rateFound = driver.FindElement(
By.XPath("//*[contains(.,'1 EUR = 1.95583 BGN')]"));
Assert.True(rateFound != null);
}
[Test]
public void Test_XECom_EurBgnCourse_ByMouse()
{
driver.Navigate().GoToUrl("https://xe.com");
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
// Choose amount "1"
driver.FindElement(By.XPath("(//input[@type='text'])[1]")).Click();
driver.FindElement(By.XPath("(//input[@type='text'])[1]")).SendKeys("1");
// Choose source currency "EUR"
driver.FindElement(By.XPath("(//input[@type='text'])[2]")).Click();
driver.FindElement(By.XPath("(//input[@type='text'])[2]")).SendKeys("eur");
driver.FindElement(By.XPath("//*[(contains(@class,'converterform-dropdown__option') or contains(@class,'ListboxOption')) and contains(.,'EUR')]")).Click();
// Choose destination currency "BGN"
driver.FindElement(By.XPath("(//input[@type='text'])[3]")).Click();
driver.FindElement(By.XPath("(//input[@type='text'])[3]")).SendKeys("bgn");
driver.FindElement(By.XPath("//*[(contains(@class,'converterform-dropdown__option') or contains(@class,'ListboxOption')) and contains(.,'BGN')]")).Click();
// Click the [Submit] button
driver.FindElement(By.XPath("//button[@type='submit'] | //a[contains(@class,'BaseButton')]")).Click();
// Assert the conversion rate is correct
var rateFound = driver.FindElement(
By.XPath("//*[contains(.,'1 EUR = 1.95583 BGN')]"));
Assert.True(rateFound != null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment