Memory
Memory is the module that allows to easily store and share data between steps.
To start using memory just import corresponing class into your tests.
To get element from storage call getValue() method with argument. If you pass simple string that getValue will return it as is.
const { Memory } = require("@cucumber-e2e/memory");
Memory.setValue("YourKey", "Your Value");
Memory.getValue("$YourKey");
You can also parse string and replace {memoryKey} patterns with memory values via parseString() method.
const { Memory } = require("@cucumber-e2e/memory");
Memory.setValue("YourKey", "Your Value");
Memory.getValue("String with {$YourKey}");
Moreover memory module implements several classes to define and store static constant and dynamical values
Define computed value
const { Memory } = require("@cucumber-e2e/memory");
const { ComputedMap } = require("@cucumber-e2e/memory");
class YourComputedMap extends ComputedMap {
constructor() {
super();
this.defineComputed(/^FUNCTION$/, () => {
return "value"
});
}
}
Memory.setComputedInstance(new YourComputedMap());
Memory.getValue("#FUNCTION");
Define constant
const { Memory } = require("@cucumber-e2e/memory");
const { ConstantMap } = require("@cucumber-e2e/memory");
class YourConstantMap extends ConstantMap {
constructor() {
super();
this.defineConstant("constantKey", "value");
this.defineFileConstant("fileConstantKey", "./test/file.txt");
}
}
Memory.setConstantsInstance(new YourConstantMap());
Memory.getValue("!constantKey");
Memory.getValue("!!fileConstantKey");