WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Use of appTopLevelWindow capability makes Clear() do nothing

Open helvian opened this issue 6 years ago • 2 comments

When attaching to a window via the 'appTopLevelWindow' capability, use of the Clear() command does nothing even though it returns a 200 OK response. When using the 'app' capability, Clear() works as intended.

This was observed in a notepad test fixture:

    [SetUp]
    public void CreateDriver()
    {
        var appCapabilities = new AppiumOptions();
        appCapabilities.AddAdditionalCapability("platformName", @"Windows");
        appCapabilities.AddAdditionalCapability("deviceName", @"WindowsPC");
        appCapabilities.AddAdditionalCapability("appTopLevelWindow", GetExistingProcessHandle());
        m_driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/"), appCapabilities);
        m_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
    }

    [Test]
    public void CheckTextBoxCanBeCleared()
    {
        //"15" is the text area on notepad
        m_driver.FindElementByAccessibilityId("15").Click();
        new Actions(m_driver).SendKeys("test").Perform();

        m_driver.FindElementByAccessibilityId("15").Clear();
        Assert.That(m_driver.FindElementByAccessibilityId("15").Text, Is.Empty);
    }

    private static string GetExistingProcessHandle()
    {
        string mainWindowHandle = null;

        var process = Process.GetProcessesByName("notepad").FirstOrDefault();
        if (process != null)
            mainWindowHandle = process.MainWindowHandle.ToString("x");

        return mainWindowHandle;
    }

The WinAppDriver responses, the first being the response upon calling Clear():

==========================================
POST /session/8A1210E3-8D58-4992-ACBE-52A54873FD9C/element/42.857144/clear HTTP/1.1
Accept: application/json, image/png
Content-Length: 2
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)

{}
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json

{"sessionId":"8A1210E3-8D58-4992-ACBE-52A54873FD9C","status":0}

and the response upon getting the text contained within the same element that has just been cleared:

==========================================
GET /session/8A1210E3-8D58-4992-ACBE-52A54873FD9C/element/42.857144/text HTTP/1.1
Accept: application/json, image/png
Cache-Control: no-cache
Host: 127.0.0.1:4723
User-Agent: selenium/3.141.0 (.net windows)


HTTP/1.1 200 OK
Content-Length: 78
Content-Type: application/json

{"sessionId":"8A1210E3-8D58-4992-ACBE-52A54873FD9C","status":0,"value":"test"}

helvian avatar Jan 20 '20 10:01 helvian

Hi @helvian what is 'appTopLevelWindow' capablity?

angad16 avatar Jan 29 '20 09:01 angad16

As seen here on this page, it basically tells Appium to look for a window with a specific window handle.

helvian avatar Jan 30 '20 09:01 helvian