|
|
|
@ -2,7 +2,7 @@ import EventEmitter from 'events' |
|
|
|
|
import { NightwatchBrowser } from 'nightwatch' |
|
|
|
|
|
|
|
|
|
class RenamePath extends EventEmitter { |
|
|
|
|
command (this: NightwatchBrowser, path: string, newFileName: string, renamedPath: string) { |
|
|
|
|
command(this: NightwatchBrowser, path: string, newFileName: string, renamedPath: string) { |
|
|
|
|
this.api.perform((done) => { |
|
|
|
|
renamePath(this.api, path, newFileName, renamedPath, () => { |
|
|
|
|
done() |
|
|
|
@ -13,9 +13,9 @@ class RenamePath extends EventEmitter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function renamePath (browser: NightwatchBrowser, path: string, newFileName: string, renamedPath: string, done: VoidFunction) { |
|
|
|
|
function renamePath(browser: NightwatchBrowser, path: string, newFileName: string, renamedPath: string, done: VoidFunction) { |
|
|
|
|
browser.execute(function (path: string) { |
|
|
|
|
function contextMenuClick (element) { |
|
|
|
|
function contextMenuClick(element) { |
|
|
|
|
const evt = element.ownerDocument.createEvent('MouseEvents') |
|
|
|
|
const RIGHT_CLICK_BUTTON_CODE = 2 // the same for FF and IE
|
|
|
|
|
|
|
|
|
@ -32,15 +32,19 @@ function renamePath (browser: NightwatchBrowser, path: string, newFileName: stri |
|
|
|
|
} |
|
|
|
|
contextMenuClick(document.querySelector('[data-path="' + path + '"]')) |
|
|
|
|
}, [path], function () { |
|
|
|
|
browser |
|
|
|
|
.click('#menuitemrename') |
|
|
|
|
.sendKeys('[data-input-path="' + path + '"]', newFileName) |
|
|
|
|
.sendKeys('[data-input-path="' + path + '"]', browser.Keys.ENTER) |
|
|
|
|
.waitForElementNotPresent('[data-path="' + path + '"]') |
|
|
|
|
.waitForElementPresent('[data-path="' + renamedPath + '"]') |
|
|
|
|
.perform(() => { |
|
|
|
|
done() |
|
|
|
|
}) |
|
|
|
|
try { |
|
|
|
|
browser |
|
|
|
|
.click('#menuitemrename') |
|
|
|
|
.sendKeys('[data-input-path="' + path + '"]', newFileName) |
|
|
|
|
.sendKeys('[data-input-path="' + path + '"]', browser.Keys.ENTER) |
|
|
|
|
.waitForElementNotPresent('[data-path="' + path + '"]') |
|
|
|
|
.waitForElementPresent('[data-path="' + renamedPath + '"]'); |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error('An error occurred:', error.message); |
|
|
|
|
// Handle error (e.g., take a screenshot, log the error, etc.)
|
|
|
|
|
} finally { |
|
|
|
|
done(); // Ensure done is called even if there's an error
|
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|