Skip to content

Commit

Permalink
issue-829: Fix TextEditor > getSelectedText is not working on macOS (#…
Browse files Browse the repository at this point in the history
…830)

Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek authored Jun 7, 2023
1 parent b68e671 commit 70f3ac4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions page-objects/src/components/editor/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,19 @@ export class TextEditor extends Editor {
*/
async getSelectedText(): Promise<string> {
const originalClipboard = clipboard.readSync();
const selection = await this.getSelection();
if (!selection) {
return '';
if(process.platform !== 'darwin') {
const selection = await this.getSelection();
if (!selection) {
return '';
}
const menu = await selection.openContextMenu();
await menu.select('Copy');
} else {
const inputarea = await this.findElement(TextEditor.locators.Editor.inputArea);
await inputarea.sendKeys(Key.chord(TextEditor.ctlKey, 'c'));
await new Promise(res => setTimeout(res, 500));
await inputarea.sendKeys(Key.UP);
}
const menu = await selection.openContextMenu();
await menu.select('Copy');
await new Promise(res => setTimeout(res, 500));
const text = clipboard.readSync();
clipboard.writeSync(originalClipboard);
Expand Down Expand Up @@ -477,6 +484,7 @@ export class TextEditor extends Editor {
* Text selection block
*/
class Selection extends ElementWithContexMenu {

constructor(el: WebElement, editor: TextEditor) {
super(el, editor);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-project/src/test/editor/textEditor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('TextEditor', function () {
expect(line).equals(6);
});

(process.platform === 'darwin' ? it.skip : it)('text can be selected', async function () {
it('selected text can be get', async function () {
const text = 'bline';
await editor.selectText(text);
expect(await editor.getSelectedText()).equals(text);
Expand Down

0 comments on commit 70f3ac4

Please sign in to comment.