如果不同的Java泛型类型参数具有相同的名称,为什么可以分配不同的类型?(If different Java generic type parameter have the same name, why it can be assigned different types?)
在oracle的官方java文档Type Inference章节中,有一个例子是这样的:
static <T> T pick(T a1, T a2) { return a2; } Serializable s = pick("d", new ArrayList<String>());
在这种情况下,类型参数是T,但通过了两种不同的类型,a1的类型是不是应该与a2相同?
In oracle's official java document, Type Inference chapter, there's an example like this:
static <T> T pick(T a1, T a2) { return a2; } Serializable s = pick("d", new ArrayList<String>());
In this case the type parameters are T but was passed two different type, shouldn't a1's type be the same as a2?
原文:https://stackoverflow.com/questions/47624283
最满意答案
waitFor函数接受选择器,函数或超时。 如果你想看看url是否等于某个东西,那就为它写一个函数。 将url作为参数传递,以便在浏览器上下文中阅读它。
const url = await page.url(); await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function
您也可以使用内置代码构建的浏览器等待url匹配。
await page.waitFor(()=> location.href === 'http://localhost:3000/blogs');
请注意,由于您正在使用
===
来匹配字符串,因此请确保包含http://
因为location.href
将使用协议输出网址。如果你想使用笑话,那么你可以使用
expect
并将其包装在一个块中。it('should contain specific url', async () => { const url = await page.url(); expect(url).toContain('localhost:3000/blogs'); });
这是一个供玩笑和木偶一起使用的文件。
The waitFor function accepts a selector, function or timeout. If you want to see if url is equal to something, then write a function for it. Pass the url as an argument so you can read it within the browser context.
const url = await page.url(); await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function
Also you can use browsers built in code to wait for url to match.
await page.waitFor(()=> location.href === 'http://localhost:3000/blogs');
Note, since you are using
===
to match a string, make sure to includehttp://
sincelocation.href
will output the url with the protocol.If you want to use jest, then you can use
expect
and wrap it in ait
block.it('should contain specific url', async () => { const url = await page.url(); expect(url).toContain('localhost:3000/blogs'); });
Here is a document for jest and puppeteer together.
相关问答
更多-
目前无法将Puppeteer与Cloud Functions结合使用,因为运行部署代码的服务器实例缺少Puppeteer所需的共享库。 你可以在这个GitHub问题中阅读 。 也看到这个问题 。 It's currently not possible to use Puppeteer with the Cloud Functions node 6 runtime because the server instances that run deployed code are lacking a shared ...
-
在最基本的层面上,POM声明每个页面都有自己的类,其中包含与该页面交互的实用程序方法。 为了通过Puppeteer实现这一点,我们使用ES6类来创建包含各自页面的实用程序方法的类。 文件夹结构 test/ main.js pages/ - HomePage.js - CartPage.js - ProductDetailPage.js HomePage.js export default class HomePage { constructor(page) { ...
-
你的Object.keys回调函数也需要使用async以便在里面使用await。 尝试改变如下 Object.keys(TEAM['premier_league']).forEach( async function(key) { // Go To Team URL await page.goto(TEAM['premier_league'][key]['url']) }); 希望能帮助到你 Your Object.keys callback function need to use a ...
-
当底层线程对象在操作系统层终止时, TThread.WaitFor()等待线程句柄( TThread.Handle属性)发出信号。 当您的Execute()方法退出后(并且在TThread.DoTerminate()被调用并退出后) TThread调用Win32 API ExitThread()函数时,会发生此信号。 您所描述的内容听起来像是遇到了阻止您的Execute()方法正确退出的死锁,即使您可能已通知FStopEvent停止了您的循环。 鉴于你已经显示的代码,这意味着要么WaitForMultipl ...
-
Java进程waitFor(Java process waitFor)[2022-12-04]
在Runtime#exec完成一个过程后,有时需要一些时间来完成IO操作。 因此,在Process#waitFor之后尝试使用Thread#sleep进行一些延迟,以便让IO处理完成。 然后尝试阅读目标文件。 希望这可以帮助。 Sometimes it take time to complete IO operations after finishing a process by Runtime#exec. so try putting some delay using Thread#sleep after ... -
你正试图迭代jQuery列表。 您应该将.forEach()替换为等价于.each() jQuery 。 You are trying to iterate over jQuery list. You should replace .forEach() with jQuery equivalent .each().
-
不支持的目标类型:布尔型,使用puppeteer waitFor函数(Unsupported target type: boolean, using puppeteer waitFor function)[2022-04-16]
waitFor函数接受选择器,函数或超时。 如果你想看看url是否等于某个东西,那就为它写一个函数。 将url作为参数传递,以便在浏览器上下文中阅读它。 const url = await page.url(); await page.waitFor((url)=> url === 'http://localhost:3000/blogs', url); // <-- use a function 您也可以使用内置代码构建的浏览器等待url匹配。 await page.waitFor(()=> locat ... -
正如您在waitFor()代码中看到的waitFor() ,每250毫秒调用一次testFx函数。 该函数应该只包含实际的检查代码而不包含加载代码。 只需将testFx includeJs()调用移出testFx函数即可。 另请注意, testFx函数必须返回示例中未包含的内容,因此它总是未定义并在一段时间后超时。 page.open("http://example.com", function (status) { if (status !== "success") { conso ...
-
casperJS css选择器:waitFor函数总是超时(casperJS css selectors: waitFor function always times out)[2023-08-30]
大部分时间都有空白,因为我们作为开发人员喜欢我们的缩进。 尝试检查HTML中是否包含该元素: return document.querySelector('...').innerHTML.indexOf('tocijan') != -1; 如果这不起作用,请检查元素是否在iframe中。 您需要使用casper.withFrame()专门切换到iframe。 Most of the time there is whitespace, because we as developers love our in ... -
如何使用headless下载文件与puppeteer:true?(How to download file with puppeteer using headless: true?)[2023-10-18]
此页面通过创建逗号分隔的字符串并强制浏览器通过设置数据类型来下载它来下载csv let uri = "data:text/csv;charset=utf-8," + encodeURIComponent(content); window.open(uri, "Some CSV"); 这在chrome上打开一个新选项卡。 您可以使用此事件并将内容物理下载到文件中。 不确定这是否是最佳方式,但效果很好。 const browser = await puppeteer.launch({ headless: ...