webdriverio / codemod

A codemod to transform Protractor into WebdriverIO tests
MIT License
25 stars 12 forks source link

Not able to convert browser.actions() class #45

Open SomeswararaoMarati opened 3 years ago

SomeswararaoMarati commented 3 years ago

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

christian-bromann commented 3 years ago

@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 commented 3 years ago

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

noobzillla commented 1 year ago

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!!!