Czinke Csaba
Czinke Csaba

Reputation: 11

Why can't windows write @ character when selenium test runs as a service?

We have a problem with Jenkins and Selenium Grid. We are testing a web application with automated tests and have a problem with running the tests as a Jenkins job. There is a computer running as a server with Windows 10 Pro and Jenkins installed. Jenkins runs as a service so when the server restarts it is running automatically. The only problem is that when Jenkins runs as a service, somehow @ characters wont be sent to input fields. So the test wants to write an email address in an input field, but the @ character won't be there and the test fails because of validation errors (testtest.hu). When Jenkins is started from cmd, the tests will pass, but this way, Jenkins won't start automatically on startup. To make sure it is not a Jenkins issue I installed Selenium Grid, but the same happens. When I run it from cmd tests will pass, but when I start it from Task scheduler they will fail. I know that the difference is when these are run from a service or task scheduler they are in Session 0 isolation, but I can't find a solution to have the tests pass in Session 0 isolation. Browser: Google Chrome in headless mode. I don't think it is an encoding problem, because characters with accents show up in the input field.

Browser: Google Chrome in headless mode.

For reproducing the error:

    [TestClass]
    public class LocalTest
    {
        [TestMethod]
        public void LocalInputTest()
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddArgument("--window-size=1920,1080");
            chromeOptions.AddArgument("--headless");
            var webDriver = new RemoteWebDriver(new Uri("http://localhost:4444/"), chromeOptions);
            webDriver.Navigate().GoToUrl("file:///C:/git/selenium-test/index.html");

            var inputText = "@éáőöüú<#&@{}>asd@";

            var element = webDriver.FindElement(By.XPath($"//*[@data-e2e-testing = 'problematic.input']"));
            element.SendKeys(inputText);

            var screenshot1 = (webDriver as ITakesScreenshot).GetScreenshot();
            screenshot1.SaveAsFile("C:/git/selenium-test/screenshot.png");

            var text = webDriver.FindElement(By.XPath($"//*[@data-e2e-testing = 'problematic.input']")).GetAttribute("value");
            Assert.AreEqual(inputText, text);
        }
    }

The test fails and i get the following error: Test fails

The screenshot shows that the input was not set correctly: Screenshot

As you can see, there are multiple characters that the test wont type in the input like: #&@.

Posting this the second time, because the first question was closed because of the lack of debugging details. I hope that this question is better and someone can help me solve this problem.

Upvotes: 1

Views: 94

Answers (1)

Czinke Csaba
Czinke Csaba

Reputation: 11

I have two workarounds right now. One is that if I change to Firefox browser the test will pass.

Other workaround is that I change the:

element.SendKeys(inputText);

to:

var actions = new Actions(webDriver);
actions.SendKeys(element, inputText);
actions.Perform();

This way the #&@ characters are getting typed in the input field.

So it seems to be a problem with Chrome browser or Chrome driver.

Upvotes: 0

Related Questions