Skip to content

[🚀 Feature]: Configurable newline character #15185

Open
@RenderMichael

Description

@RenderMichael

Feature and motivation

I have a test which reads an element's text and asserts that it contains the expected results. This text contains newlines.

I am getting different results depending on whether the tests run on macOS or on Windows. The newlines are being modified into the native newline characters (\n or \r\n, respectively).

I would like to configure a newline character to make my tests run consistently.

Note: I am using the .NET bindings, I am unsure if this happens on other bindings or if this is a .NET-specific ask

API proposal:

public class DriverOptions
{
+    public string? NewLine { get; set; }
}

Usage example

string Expected = "Selenium Clients and WebDriver Language Bindings\r\nIn order to create scripts that interact with the Selenium Server (Remote WebDriver) or create local Selenium WebDriver scripts, you need to make use of language-specific client drivers.\r\nWhile language bindings for other languages exist, these are the core ones that are supported by the main project hosted on GitHub.";

var options = new ChromeOptions();
options.NewLine = "\r\n"; // Without this, the test fails when running on macOS

using var driver = new ChromeDriver();

driver.Url = "https://www.selenium.dev/downloads/";

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var paragraph = wait.Until(driver => driver.FindElement(By.XPath("/html/body/div/main/div[2]/div/div")));

Assert.That(paragraph.Text, Is.EqualTo(Expected));

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-enhancementSomething could be better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions