Javascript 如何在承诺中获得价值

Javascript 如何在承诺中获得价值,javascript,selenium,Javascript,Selenium,告诉我如何在描述函数中使用dataTest:( 有几种方法可以实现这一点,其中之一是将文件的读取包含在一个函数中,该函数返回预期结果,然后在您的描述中调用它。这意味着在func中返回dataTest?然后我可以在任何地方使用dataTest?我尝试过,但有错误dataTest未定义:(xlsxFile(“./src/scenario/Khanh.xlsx”).then((rows)=>{const dataTest=rows[0][1];return dataTest;});descriptio

告诉我如何在描述函数中使用dataTest:(


有几种方法可以实现这一点,其中之一是将文件的读取包含在一个函数中,该函数返回预期结果,然后在您的描述中调用它。

这意味着在func中返回dataTest?然后我可以在任何地方使用dataTest?我尝试过,但有错误dataTest未定义:(
xlsxFile(“./src/scenario/Khanh.xlsx”).then((rows)=>{const dataTest=rows[0][1];return dataTest;});description(“EZT Admin Login”,async()=>{console.log(“dataTest”,dataTest”);它(“should read excel file”,async()=>{};});
您需要将它放在函数getDataTest(){*您的代码**}这样的函数中,然后在需要的任何地方调用getDataTest函数
xlsxFile('./src/scenario/Khanh.xlsx').then((rows) => {
    const dataTest = rows[0][1];
   })  

describe("EZT Admin Login", async () => {
    // console.log('obj', Array.from(obj))

  it("should read excel file  ", async () => {
    
  });
});