"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/dotnet/test/common/SvgElementTest.cs" (17 Feb 2023, 2588 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 using System.Collections.Generic;
    2 using System.Collections.ObjectModel;
    3 using NUnit.Framework;
    4 
    5 namespace OpenQA.Selenium
    6 {
    7     [TestFixture]
    8     public class SvgElementTest : DriverTestFixture
    9     {
   10         [Test]
   11         [IgnoreBrowser(Browser.Firefox, "wontfix: https://bugzilla.mozilla.org/show_bug.cgi?id=1428780")]
   12         public void ShouldClickOnGraphVisualElements()
   13         {
   14             if (TestUtilities.IsOldIE(driver))
   15             {
   16                 Assert.Ignore("SVG support only exists in IE9+");
   17             }
   18 
   19             driver.Url = svgPage;
   20             IWebElement svg = driver.FindElement(By.CssSelector("svg"));
   21 
   22             ReadOnlyCollection<IWebElement> groupElements = svg.FindElements(By.CssSelector("g"));
   23             Assert.AreEqual(5, groupElements.Count);
   24 
   25             groupElements[1].Click();
   26             IWebElement resultElement = driver.FindElement(By.Id("result"));
   27             WaitFor(() => { return resultElement.Text == "slice_red"; }, "Element text was not 'slice_red'");
   28             Assert.AreEqual("slice_red", resultElement.Text);
   29 
   30             groupElements[2].Click();
   31             resultElement = driver.FindElement(By.Id("result"));
   32             WaitFor(() => { return resultElement.Text == "slice_green"; }, "Element text was not 'slice_green'");
   33             Assert.AreEqual("slice_green", resultElement.Text);
   34         }
   35 
   36         [Test]
   37         public void ShouldClickOnGraphTextElements()
   38         {
   39             if (TestUtilities.IsOldIE(driver))
   40             {
   41                 Assert.Ignore("SVG support only exists in IE9+");
   42             }
   43 
   44             driver.Url = svgPage;
   45             IWebElement svg = driver.FindElement(By.CssSelector("svg"));
   46             ReadOnlyCollection<IWebElement> textElements = svg.FindElements(By.CssSelector("text"));
   47 
   48             IWebElement appleElement = FindAppleElement(textElements);
   49             Assert.That(appleElement, Is.Not.Null);
   50 
   51             appleElement.Click();
   52             IWebElement resultElement = driver.FindElement(By.Id("result"));
   53             WaitFor(() => { return resultElement.Text == "text_apple"; }, "Element text was not 'text_apple'");
   54             Assert.AreEqual("text_apple", resultElement.Text);
   55         }
   56 
   57         private IWebElement FindAppleElement(IEnumerable<IWebElement> textElements)
   58         {
   59             foreach (IWebElement currentElement in textElements)
   60             {
   61                 if (currentElement.Text.Contains("Apple"))
   62                 {
   63                     return currentElement;
   64                 }
   65             }
   66 
   67             return null;
   68         }
   69     }
   70 }