codemod icon indicating copy to clipboard operation
codemod copied to clipboard

Not able to convert browser.actions() class

Open SomeswararaoMarati opened this issue 4 years ago • 3 comments

Hi,

Migrate Command is giving an error while converting the following.

await browser.actions().doubleClick(this.btnDoubleClick).perform(); await browser.actions().mouseDown(this.btnDoubleClick).mouseUp().perform(); await browser.actions().mouseMove(this.btnDoubleClick).click().perform();

ERR ./protractorTests/pages/buttons.page.js Transformation error (Error transforming ./protractorTests/pages/buttons.page.js:16) Error transforming ./protractorTests/pages/buttons.page.js:16

    await browser.actions()
            ^

Can not transform "actions" command as it differs too much from the WebdriverIO implementation. We advise to refactor this code.

For more information on WebdriverIOs replacement command, see https://webdriver.io/docs/api/webdriver#performactions at ./protractorTests/pages/buttons.page.js:16:14 All done. Results: 1 errors 0 unmodified 0 skipped 0 ok

action commands from protractor are ot able to migrate

SomeswararaoMarati avatar Aug 11 '21 12:08 SomeswararaoMarati

@SomeswararaoMarati as mentioned in the error message it is not feasible to transform these statements. They are too different in their syntax. Therefor unfortunately these lines have to be migrated manually.

christian-bromann avatar Aug 11 '21 12:08 christian-bromann

I will keep this open in case someone wants to tackle this challenge. PRs welcome!

christian-bromann avatar Aug 11 '21 12:08 christian-bromann

There is a work around on this issue, by commenting out browser.actions() or Key, and migrate the script. if this a large file then you can create a file that will point where you need to comment out.

EX:

const fs = require("fs");

function commentOutBrowserActions(filePath){
    try {
        if (fs.existsSync(filePath)) {
            let file = fs.readFileSync(filePath, 'utf8');
            let lines = file.split("\n");

            for(let i = 1; i < lines.length; i++){
                if (lines[i].includes("browser.actions()") || lines[i].includes("Key.") || lines[i].includes('flow')) {
                    lines[i] = ">>>>>>> Fix Me" + lines[i];
                }
            }

            let commentedFile = lines.join("\n");
            fs.writeFileSync(filePath, commentedFile, 'utf8');
            console.log("Done");
        }
    } catch (error) {
        console.log(error);
    }
}

const filePath = process.argv[2];
commentOutBrowserActions(filePath);

You can run this file using node index.js file/path After it is done executing it will be something like this

>>>>>>> Fix Me        browser.actions()

Hope this helps!!!

noobzillla avatar Jan 25 '23 19:01 noobzillla