microsoft / WinAppDriver

Windows Application Driver
MIT License
3.68k stars 1.4k forks source link

Test fails when next line (\n) is added in notepad application #140

Open gaurang011 opened 7 years ago

gaurang011 commented 7 years ago
using System;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.iOS;

namespace NotepadTest
{
    [TestClass]
    public class Scenario
    {
        protected const string AppDriverUrl = "http://127.0.0.1:4723";
        protected const string TextValue1 = "name,username,email,password\n";
        protected const string TextValue2 = "sample,sample123,sample@gmail.com,Test@123";
        protected const string TextValue3 = TextValue1 + TextValue2;
        protected const string NotepadAppId = @"C:\Windows\System32\notepad.exe"; 
        protected const string ExplorerAppId = @"C:\Windows\System32\explorer.exe";
        protected const string TestFileName = "NotepadTestOutputFile.csv"; 
        protected const string TargetSaveLocation = @"C:\Users\DELL09\Documents\";
        protected static IOSDriver<IOSElement> NotepadSession;

        [ClassInitialize]
        public static void Setup(TestContext context)
        {
            // Launch Notepad Classic Windows Application
            DesiredCapabilities appCapabilities = new DesiredCapabilities();
            appCapabilities.SetCapability("app", NotepadAppId);
            NotepadSession = new IOSDriver<IOSElement>(new Uri(AppDriverUrl), appCapabilities);
            Assert.IsNotNull(NotepadSession);
        }

        [TestMethod]
        public void BasicScenario()
        {
            // Verify that Notepad is started with untitled new file
            Assert.AreEqual("Untitled - Notepad", NotepadSession.Title); 
            EnterText();
            SaveFile();

            // Verify that Notepad has saved the edited text file with the given name
            Thread.Sleep(1000); // Wait for 1 second until the window title is updated
            Assert.AreEqual(TestFileName + " - Notepad", NotepadSession.Title);
        }

        public void EnterText()
        {
            // Enter text into the edit field
            var editBox = NotepadSession.FindElementByClassName("Edit");
            editBox.SendKeys(TextValue3);
            Assert.AreEqual(TextValue3, editBox.Text);

            //Enter TimeStamp
            //NotepadSession.FindElementByName("Edit").Click();
            //NotepadSession.FindElementByName("Time/Date").Click();
            //Assert.AreNotEqual(TextValue, editBox.Text);
        }

        public void SaveFile()
        {
            NotepadSession.FindElementByName("File").Click();
            NotepadSession.FindElementByName("Save As...").Click();

            System.Threading.Thread.Sleep(1000); // Wait for 1 second until the save dialog appears
            var fileNameBox = NotepadSession.FindElementByAccessibilityId("FileNameControlHost");
            fileNameBox.SendKeys(TargetSaveLocation + TestFileName);
            NotepadSession.FindElementByName("Save").Click();

            // Confirm save as dialog in case there's leftover test file from previous test run
            try
            {
                Thread.Sleep(1000); // Wait for 1 second until the dialog comes up
                var confirmSaveAsDialog = NotepadSession.FindElementByName("Confirm Save As");
                confirmSaveAsDialog.FindElementByName("Yes").Click();
            }
            catch { }
        }
    }
}

I am getting following error

Test Name: BasicScenario Test FullName: NotepadTest.Scenario.BasicScenario Test Source: C:\Users\DELL09\Documents\Visual Studio 2015\Projects\WinAppDriver-master\Samples\C#\NotepadTest\Scenario.cs : line 34 Test Outcome: Failed Test Duration: 0:00:07.2690552

Result StackTrace:
at NotepadTest.Scenario.EnterText() in C:\Users\DELL09\Documents\Visual Studio 2015\Projects\WinAppDriver-master\Samples\C#\NotepadTest\Scenario.cs:line 51 at NotepadTest.Scenario.BasicScenario() in C:\Users\DELL09\Documents\Visual Studio 2015\Projects\WinAppDriver-master\Samples\C#\NotepadTest\Scenario.cs:line 38 Result Message:
Assert.AreEqual failed. Expected:<name,username,email,password sample,sample123,sample@gmail.com,Test@123>. Actual:<name,username,email,password sample,sample123,sample@gmail.com,Test@123>.

gaurang011 commented 7 years ago

Hi, Any updates?

yodurr commented 7 years ago

Hi @gaurang011

The newline issues I'm repro'ing are:

So there's definitely a bug here but will need to investigate with the team before knowing what we can do to address this behavior.

In the meantime to get your test passing you can strip the \r from the editBox.Text response or have a separate const string which includes the \r and use this string to compare the editBox.Text.

xied75 commented 6 years ago

Is this fixed now?

sayedsaad07 commented 4 years ago

This issue is not fixed yet. I created a new issue in case this issue is closed [https://github.com/microsoft/WinAppDriver/issues/1032]