Cypress Plugin for Hostname Is Empty String #15004
-
I created a plugin in support/index.js
Basically I want to store the hostname in the environment variable testing_computer. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@tgf-coder you have to do this within the plugins file: https://docs.cypress.io/guides/tooling/plugins-guide.html#Use-Cases Your current code is in the "support file" which only runs within the browser and not on your local system. |
Beta Was this translation helpful? Give feedback.
-
I pushed my code into https://github.com/cypress-io/cypress-test-tiny/tree/osname // cypress/plugins/index.js
const os = require('os');
module.exports = (on, config) => {
config.env.testing_computer = os.hostname();
console.log('config env is', config.env)
return config;
} // cypress/integration/spec.js
/// <reference types="cypress" />
it('has hostname', () => {
expect(Cypress.env('testing_computer')).to.be.a('string').and.not.be.empty
}) When Cypress opens you can find the hostname under Settings / configuration / env object And in the test you can see the value |
Beta Was this translation helpful? Give feedback.
-
Solved. I ended up clearing the contents of the plugin/index.js file and everything is now working. |
Beta Was this translation helpful? Give feedback.
@tgf-coder you have to do this within the plugins file: https://docs.cypress.io/guides/tooling/plugins-guide.html#Use-Cases
Your current code is in the "support file" which only runs within the browser and not on your local system.