Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🚀 Feature]: Configurable newline character #15185

Open
RenderMichael opened this issue Jan 30, 2025 · 2 comments
Open

[🚀 Feature]: Configurable newline character #15185

RenderMichael opened this issue Jan 30, 2025 · 2 comments

Comments

@RenderMichael
Copy link
Contributor

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/";

Thread.Sleep(TimeSpan.FromSeconds(5));
var paragraph = driver.FindElement(By.XPath("/html/body/div/main/div[2]/div/div")).Text;

Assert.That(paragraph, Is.EqualTo(Expected));
Copy link

@RenderMichael, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@atmaxinger
Copy link

This would be a nice feature, as I've also been stung by this before. This seems to be the offending line:

valueString = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants