Monaco-editor: Using selenium in C#, how to write code to do basic input/edit/delete?

Created on 23 Mar 2017  路  4Comments  路  Source: microsoft/monaco-editor

Working on e2e automation test using Selenium.

The editor is not a text area. Each line is a separated div element.
Given some "code" in string format(or retrieve it from some static files) how can I do the input/edit/delete? Anyone please has some ideas or experience? Do I have to parse the input and update the inner html following the original format?

Most helpful comment

All 4 comments

The editor I/O is done via a <textarea> that always has focus. If you click in an editor, the browser focus resides in a very tiny <textarea>. In 0.8.3. the textarea is placed at the top left of the editor, in the upcoming release the <textarea> will move with the editor's primary cursor (when it is visible). You can find the <textarea> by clicking in an editor and using document.activeElement in a browser console.

To simulate editing, etc. you would need to send correct browser events to the <textarea>.

Finding this issue helped me a lot, thank you for adding the notes. I suppose there are two items here:

  1. Selenium (and similar) API's for sending events to the browser elements of interest
  2. How to interact with the editor programmatically (via its <textarea> element

I think the first is clearly out of scope as far as documentation goes, but I is there somewhere the second point is / could be documented?.

On the first point, in case this helps anyone else perusing this issue, sending the events to the browser could use seleniums sendKeys or (in my case) WebdriverIO's setValue method. I have a spectron test that does this:

async function setText(client: SpectronClient, text: string) {
    await client.setValue(`.monaco-editor textarea`, text);
}

@joaomoreno Perhaps you remember what you had to do to get spectron to like our editor?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SoftTimur picture SoftTimur  路  3Comments

andreymarchenko picture andreymarchenko  路  3Comments

poloten4uk picture poloten4uk  路  3Comments

fabiospampinato picture fabiospampinato  路  3Comments

zeegin picture zeegin  路  3Comments