Created
November 15, 2012 03:13
-
-
Save margusmartsepp/4076425 to your computer and use it in GitHub Desktop.
C# selenium log in / log out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using NUnit.Framework; | |
| using OpenQA.Selenium; | |
| using OpenQA.Selenium.Firefox; | |
| using OpenQA.Selenium.Support.UI; | |
| namespace Testimine | |
| { | |
| [TestFixture] | |
| public class Program | |
| { | |
| IWebDriver browser; | |
| WebDriverWait w; | |
| [SetUp] | |
| public void Init() { | |
| browser = new FirefoxDriver(); | |
| w = new WebDriverWait(browser, new TimeSpan(0, 0, 5)); | |
| } | |
| [TearDown] | |
| public void Dispose() { | |
| browser.Quit(); | |
| } | |
| private void logIn() { | |
| browser.Navigate().GoToUrl("http://www.cv.ee/login"); | |
| browser.FindElement(By.Id("kasutajanimi")).SendKeys("bing"); | |
| browser.FindElement(By.Id("parool")).SendKeys("bing"); | |
| browser.FindElement(By.ClassName("btn_green_submit")).Click(); | |
| } | |
| [Test] | |
| public void LogIn() | |
| { | |
| logIn(); | |
| Assert.IsTrue(browser.FindElement(By.TagName("body")).Text.Contains("Ints Piratsioon")); | |
| } | |
| [Test] | |
| public void LogOut() | |
| { | |
| logIn(); | |
| browser.FindElement(By.LinkText("Välju")).Click(); | |
| Assert.IsTrue(!browser.FindElement(By.TagName("body")).Text.Contains("Ints Piratsioon")); | |
| } | |
| static void Main(string[] args) | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment