开玩笑-博览会-木偶师 - 获得"Oh no! It looks like JavaScript is not enabled in your browser"



当我按照jest expo puppeteer文档中的指导方针在jest-expo-puppeteer中运行一个非常简单的样本测试时,我不断收到一个奇怪的错误日志,似乎找不到任何预期的元素。所以我试着打印出页面:

// Import the config so we can find the host URL
import config from '../../jest-puppeteer.config'
let response
beforeEach(async () => {
// Jest puppeteer exposes the page object from Puppeteer
response = await page.goto(config.url)
})
it(`should have welcome string`, async () => {
const html = await page.evaluate(() => document.documentElement.outerHTML)
console.log(html)
await expect(page).toMatchElement('div[data-testid="welcome"]', { text: 'Welcome!' })
})

页面结果显示文本Oh no! It looks like JavaScript is not enabled in your browser.:

...
<body>
<!-- 
A generic no script element with a reload button and a message.
Feel free to customize this however you'd like.
-->
<noscript>
<form
action=""
style="background-color:#fff;position:fixed;top:0;left:0;right:0;bottom:0;z-index:9999;"
>
<div
style="font-size:18px;font-family:Helvetica,sans-serif;line-height:24px;margin:10%;width:80%;"
>
<p>Oh no! It looks like JavaScript is not enabled in your browser.</p>
<p style="margin:20px 0;">
<button
type="submit"
style="background-color: #4630EB; border-radius: 100px; border: none; box-shadow: none; color: #fff; cursor: pointer; font-weight: bold; line-height: 20px; padding: 6px 16px;"
>
Reload
</button>
</p>
</div>
</form>
</noscript>
<!-- The root element for your Expo app. -->
<div id="root"><div class="css-view-1dbjc4n r-flex-13awgt0 r-pointerEvents-12vffkv"><div class="css-view-1dbjc4n r-flex-13awgt0 r-pointerEvents-12vffkv"></div></div></div>
<script src="/static/js/bundle.js"></script>

</body></html>
...

无头执行和浏览器内执行都会发生这种情况。

所以看起来Javascript被关闭了。page对象是由jest-expo-puppeteer在内部创建的,所以我想知道:

  • 如何在jest-expo-puppeteer中打开JavaScript
  • 这不是默认情况下应该打开吗?也许我在设置中遗漏了什么

我自己找到了答案:

  • 内容Oh no! It looks like JavaScript is not enabled in your browser.始终存在于react本机文件中。在服务器上,它似乎是一个备份(如果浏览器确实没有启用JavaScript,它就会显示出来(
  • 因此,没有必要打开JavaScript。事实上,JavaScript是默认打开的
  • 我无法检测页面中元素的原因是JavaScript执行尚未完成。当我放入一个等待语句时,它会很好地工作,例如:
it(`should have welcome string`, async () => {
const welcome = await page.waitForSelector('div[data-testid="welcome"]')
const text = await (await welcome.getProperty('innerHTML')).jsonValue()
await expect(text).toMatch('Welcome!')
})

相关内容