Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98819

How to fix test automation code using Selenium with C#?

$
0
0

I am working on automated tests for the first time using Selenium with C#. I am following some instructions as a beginner from this link. However, it is not working. It says 1 Test failed. I have the following code:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;


namespace OnlineStore.TestCases
{
    class LogInTest
    {
        [Test]
        public void Test()
        {
            IWebDriver driver = new ChromeDriver();
            driver.Url = "http://www.store.demoqa.com";

            // Find the element that's ID attribute is 'account'(My Account) 
            driver.FindElement(By.XPath(".//*[@id='account']/a")).Click();

            // Find the element that's ID attribute is 'log' (Username)
            // Enter Username on the element found by above desc.
            driver.FindElement(By.Id("log")).SendKeys("testuser_1");

            // Find the element that's ID attribute is 'pwd' (Password)
            // Enter Password on the element found by the above desc.
            driver.FindElement(By.Id("pwd")).SendKeys("Test@123");

            // Now submit the form.
            driver.FindElement(By.Id("login")).Click();

            // Find the element that's ID attribute is 'account_logout' (Log Out)
            driver.FindElement(By.XPath(".//*[@id='account_logout']/a")).Click();

            // Close the driver
            driver.Quit();

        }
    }
}

And the following message:

[10/6/2019 5:05:53 AM Informational] Executing test method 'OnlineStore.TestCases.LogInTest.Test'
[10/6/2019 5:05:53 AM Informational] ------ Run test started ------
[10/6/2019 5:05:54 AM Informational] NUnit Adapter 3.15.1.0: Test execution started
[10/6/2019 5:05:54 AM Informational] Running selected tests in C:\Users\enead\source\repos\OnlineStore\OnlineStore\bin\Debug\OnlineStore.dll
[10/6/2019 5:05:55 AM Informational]    NUnit3TestExecutor converted 1 of 1 NUnit test cases
[10/6/2019 5:05:55 AM Informational] NUnit Adapter 3.15.1.0: Test execution complete
[10/6/2019 5:05:55 AM Informational] ========== Run test finished: 1 run (0:00:01.8817664) ==========

I've searched multiple websites to find an answer but without success. What is wrong? What can I do?
Edits
I am providing some screenshots.

1 Test failed

Error message

Error after specifying the location of the driver


Viewing all articles
Browse latest Browse all 98819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>