Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.1k views
in Technique[技术] by (71.8m points)

javascript - How to use aws credentials using cypress

I'm currently having difficulty finding a way to integrate my AWS credentials into my cypress tests when running cypress tests. The static approach works in hardcording your credentials into config.update . However I wish to opt for a more dynamic approach using my local credentials . I have managed to write a working script when executing from node successfully creates temp credentials. But stuck on how to implement the credentials into cypress AWS.config.update()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By using Cypress cy.task Simply define your aws-sdk command in plugins/index.js on task and make sure to include AWS.config.update({region: *REGIONNAME*}) And set your cy.task(doSomething) in your browser test.

Plugin/index.js

on('task', {

getOrg(orgid) {
var AWS = require("aws-sdk");
AWS.config.update({region: *REGIONNAME*}

//e.g AWS SDK command to get a organisation id from dynamodb

Return *null or value or true etc*
 }
}


Cypress test example test.js

orgid = 123;
cy.task ("getOrg",orgid)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...