{"id":690,"date":"2020-02-27T14:29:51","date_gmt":"2020-02-27T14:29:51","guid":{"rendered":"https:\/\/rologix.com\/wp\/?p=690"},"modified":"2020-02-27T16:47:43","modified_gmt":"2020-02-27T16:47:43","slug":"selenium-und-c","status":"publish","type":"post","link":"https:\/\/www.rologix.com\/wp\/?p=690","title":{"rendered":"Selenium und C#"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-style-default is-layout-flow wp-block-quote-is-layout-flow\"><p>Selenium is an umbrella project for a range of tools and libraries that enable and support the automation of web browsers.  <\/p><cite>https:\/\/www.selenium.dev\/documentation\/en\/<\/cite><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p> Mit Selenium ist es m\u00f6glich, Interaktionen mit einer Webanwendung aufnehmen zu lassen und diese&nbsp;<a href=\"https:\/\/de.wikipedia.org\/wiki\/Softwaretest\">Tests<\/a>&nbsp;automatisiert beliebig oft zu wiederholen. Es kann vor allem Entwicklern von Webanwendungen sehr viel Tipparbeit abnehmen \u2013 beispielsweise beim Ausf\u00fcllen von&nbsp;<a href=\"https:\/\/de.wikipedia.org\/wiki\/Webformular\">Webformularen<\/a>&nbsp;\u2013 und macht das Testen dadurch schneller, flexibler und verl\u00e4sslicher. <\/p><cite> <a href=\"https:\/\/de.wikipedia.org\/wiki\/Selenium\">https:\/\/de.wikipedia.org\/wiki\/Selenium<\/a> <\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">In K\u00fcrze<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.selenium.dev\/\">Selenium <\/a>ist wunderbar um wiederkehrendes Klicken und Formularausf\u00fcllen zu &#8222;automatisieren&#8220;. Der Code welcher <a href=\"https:\/\/www.selenium.dev\/\">Selenium <\/a>verwendet (Java, <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/tour-of-csharp\/\">C#<\/a>, &#8230;.) startet einen &#8222;eigenen&#8220; Browser (Chrom, Firefox, IE, etc.) mit dem aus dem Code heraus Benutzerinteraktionen (klicken, Daten ausf\u00fcllen, etc.) ausgef\u00fchrt und gesteuert werden k\u00f6nnen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nun wird meist davon gesprochen, dass damit Tests automatisiert werden k\u00f6nnen. Es ist aber auch denkbar, dass mittels  <a href=\"https:\/\/www.selenium.dev\/\">Selenium<\/a> spezifische Daten gesucht werden k\u00f6nnen die nicht \u00fcber eine konventionelle Schnittstelle zur Verf\u00fcgung gestellt werden. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wir verwenden <a href=\"https:\/\/www.selenium.dev\/\">Selenium<\/a> zusammen mit <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/tour-of-csharp\/\">C#<\/a> um \u00fcber ein Web-Frontend gewisse Daten zu orchestrieren. Die Daten die dabei \u00fcber das Web-Frontend gesucht werden, sind sonst nicht automatisiert abrufbar und w\u00fcrden jeweils durch eine Person gesucht und zusammengefasst werden m\u00fcssen. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Einstieg<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">      \/\/ einen Webdriver instanzieren\n      IWebDriver driver = new ChromeDriver();\n\n      \/\/ Webseite \u00f6ffnen\n      driver.Navigate().GoToUrl(homeURL);\n\n      \/\/ Elemente auf der Seite suchen mit\n      IWebElement element = driver.FindElement(By.ClassName(\"className\"));\n      IWebElement element = driver.FindElement(By.CssSelector(\"css\"));\n      IWebElement element = driver.FindElement(By.Id(\"id\"));\n      IWebElement element = driver.FindElement(By.LinkText(\"text\"));\n      IWebElement element = driver.FindElement(By.Name(\"name\"));\n      IWebElement element = driver.FindElement(By.PartialLinkText(\"pText\"));\n      IWebElement element = driver.FindElement(By.TagName(\"input\"));\n      IWebElement element = driver.FindElement(By.XPath(\"\/\/*[@id='editor']\"));\n\n      \/\/ Auf ein Element warten\n      wait.Until(driver =&gt; driver.FindElement(By.XPath(xPath)));\n\n      \/\/ Mit Elementen \"spielen\"\n      element.SendKeys(\"bspw.: etwas in ein Textfeld schreiben\");\n      element.Click();   \/\/ auf einen Button, einen Link oder ein div klicken<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tips und Tricks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">F\u00fcr Chrom wie auch Firefox gibt es Selenium IDE mit denen &#8222;einfachere&#8220; Benutzerinteraktionen aufgezeichnet werden k\u00f6nnen. (<a href=\"https:\/\/chrome.google.com\/webstore\/detail\/selenium-ide\/mooikfkahbdckldjjndioackbalphokd\">Chrom Selenium IDE<\/a>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Visual Studio NuGet hat  DotNetSeleniumExtras.WaitHelpers um das Warten auf bestimmte Web-Inhalte pr\u00e4ziser machen zu k\u00f6nnen. So kann dann zum Beispiel folgenderma\u00dfen auf ein Element gewartet werden bis es geklikt werden kann: <em>wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(xPath))).Click();<\/em><\/p>\n\n\n\n<p class=\"has-normal-font-size wp-block-paragraph\"><a href=\"https:\/\/www.rologix.com\/wp\/?p=699\">Elemente Suchen:<\/a> (bspw: WebElement outer = driver.findElement(By.anything(&#8222;whatever&#8220;));)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium is an umbrella project for a range of tools and libraries that enable and support the automation of web browsers. https:\/\/www.selenium.dev\/documentation\/en\/ Mit Selenium ist es m\u00f6glich, Interaktionen mit einer Webanwendung aufnehmen zu lassen und diese&nbsp;Tests&nbsp;automatisiert beliebig oft zu wiederholen. Es kann vor allem Entwicklern von Webanwendungen sehr viel Tipparbeit<a class=\"moretag\" href=\"https:\/\/www.rologix.com\/wp\/?p=690\"> Weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[32,23,31,33],"class_list":["post-690","post","type-post","status-publish","format-standard","hentry","category-technik","tag-automatisierung","tag-c","tag-selenium","tag-selenium-ide"],"_links":{"self":[{"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=690"}],"version-history":[{"count":11,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":705,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/690\/revisions\/705"}],"wp:attachment":[{"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rologix.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}