0

I must open a terminal in order to login to the Cloud. That terminal stays open. The question is can I execute a shell script in that terminal window from Cypress. I've researched .exec and task, but neither seem like they'd work. TIA.

  • Do you need to login into Cypress Cloud? – Harsh nahta Aug 24 '23 at 05:13
  • No, not Cypress Cloud. The real key is I have to have the terminal already opened. Then send a system command to it which launches a shell script in the opened terminal. The way I understand it, cy.exec would launch the terminal for you and that won't work in my situation. – Exdunepilot Aug 24 '23 at 15:50

2 Answers2

1

One possibility to try is Cypress Module API.

You would create a Node script and adapt this answer How to run shell script file using nodejs.

The exec command opens asynchronously, so you would want to await it before invoking Cypress.

const util = require('util')
const exec = util.promisify(require('child_process').exec)

async function runShellThenCypress() {
  try {
    const { stdout, stderr } = await exec('sh login.sh')
    console.log('stdout:', stdout)
    console.log('stderr:', stderr)

    const cypress = require('cypress')
    cypress.open({
      config: {
        baseUrl: 'http://localhost:8080',
      },
    })
  } catch (e) {
    console.error(e); 
  }
}
runShellThenCypress()
Lola Ichingbola
  • 3,035
  • 3
  • 16
0

Cypress executes code in the browser and the browser can't launch ternimal. Write a script that launches the terminal and opens cypress afterwards

Stratos Ion
  • 504
  • 3
  • 18