Working on testing with Selenium and Chrome.
I have a JavaScript array called dates
with two elements, an empty array named allDates
, and the following code snippet:
dates.forEach(async date => {
console.log("🚀 ~ file: runSelenium.js ~ line 42 ~ position", await date.getText());
let newDate = await date.getText();
console.log("🚀 ~ file: runSelenium.js ~ line 44 ~ newDate", newDate)
allDates.push(newDate);
})
console.log("🚀 ~ file: runSelenium.js ~ line 47 ~ allDates", allDates)
However, the output appears as follows:
🚀 ~ file: runSelenium.js ~ line 47 ~ allDates []
✓ First test (678ms)
🚀 ~ file: runSelenium.js ~ line 42 ~ position 26-02-2021
🚀 ~ file: runSelenium.js ~ line 42 ~ position 06.11.2020
It's strange that the last console.log appears first. The main issue is that the second console.log (the one with line 44
) is missing completely.
I attempted different ways to assign data to the newDate
variable such as:
let newDate = (await date.getText()).toString();
let newDate = await date.getAttribute('value');
let newDate = (await date.getAttribute('value')).toString();
Unfortunately, none of the above approaches worked.
So, I have a few questions:
- How can I adjust this to successfully store the
newDate
variable in an array? - Why isn't the console.log referencing
line 44
displayed, even when it should be empty? - What could be causing the incorrect order of console.logs and the test name?