我正在寻找一个用Java编写的爬行工具来检测我们网站中的无效网址.
难点在于,大部分URL都是使用javaScript,CSS3和Ajax完成的.所以只是获取网站的网址内容是行不通的.
理想的是无头工具,能够执行javaScript,CSS样式和AJAX调用,并吐出它所访问的各种URL.
我确实意识到这是一个很高的要求,但也许它存在于某个地方?
有没有在线网站我们可以在线使用Underscore或Handlebar模板而无需下载任何内容?
我正在使用TestCafe 0.23.3.我正在尝试验证元素是否已启用或禁用.以下是禁用元素时的HTML节点:
<button class="MuiButtonBase-root-415 MuiButtonBase-disabled-416 MuiButton-root-3719 MuiButton-text-3721 MuiButton-textPrimary-3722 MuiButton-flat-3724 MuiButton-flatPrimary-3725 MuiButton-disabled-3739" tabindex="-1" type="button" disabled=""><span class="MuiButton-label-3720">Add Person</span></button>
Run Code Online (Sandbox Code Playgroud)
以下是元素启用时的HTML节点:
<button class="MuiButtonBase-root-415 MuiButton-root-7365 MuiButton-text-7367 MuiButton-textPrimary-7368 MuiButton-flat-7370 MuiButton-flatPrimary-7371" tabindex="0" type="button"><span class="MuiButton-label-7366">Add Person</span><span class="MuiTouchRipple-root-778"></span></button>
Run Code Online (Sandbox Code Playgroud)
这是我的TestCafe代码来验证元素:
.expect(Selector('button').withText('Add Person').hasAttribute('disabled'))
.ok();
Run Code Online (Sandbox Code Playgroud)
上面的TestCafe代码传递了元素的启用/禁用状态,这是不正确的,因为预期的结果是检查元素是否被禁用.我不确定这里有什么问题.
有人可以使用testcafe(fixtureEach)找到最合适的方法来运行具有不同前提条件的相同夹具的最佳方法吗?
鉴于我有以下固定装置:
fixture('[Test] My Page')
.meta({ env: 'aat', mobile: 'true', author: 'me' })
.beforeEach(async t => {
await t.navigateTo(myPage.url)
await waitForReact(10000)
})
test('Page should load all data successfully', async t => {
const { Query: queries } = await t.ctx.graphQLTools.mockManagementClient.getCalls()
for (const q of Object.keys(queries)) {
for (const { args, context } of Object.keys(queries[q])) {
await t.expect(queries[q][args]).typeOf('undefined')
await t.expect(queries[q][context]).typeOf('undefined')
}
}
})
Run Code Online (Sandbox Code Playgroud)
在上面的代码示例中,我需要多次运行此测试:
我已经尝试了以下代码,但是当我在夹具中进行多个测试需要检查时,它看起来很麻烦,并且会带来复杂性(摘自https://testcafe-discuss.devexpress.com/t/multiple-用不同的数据执行一次测试/ 219):
const a = ['anonymous', 'logged In']
for (const …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Chrome上的模式获取文本。使用控制台,我可以获取内部文本,如下所示:
document.querySelector('.my-form > a').innerText
// returns http://a-url.com
Run Code Online (Sandbox Code Playgroud)
现在,在测试中,我可以使用
const myText = Selector('.my-form > a').innerText;
await t
.expect(myText).contains('url');
Run Code Online (Sandbox Code Playgroud)
我什至可以点击该网址
await t.click(myText);
Run Code Online (Sandbox Code Playgroud)
但是例如,我不能将内部文本放入变量中。我尝试从这篇文章中使用ClientFunction
const getUrl = ClientFunction(() => document.querySelector('.my-form > a').innerText);
test('My Test', async t => {
const text = await getUrl();
console.log(text);
});
// this results in
// TypeError: Cannot read property 'innerText' of null
Run Code Online (Sandbox Code Playgroud)
并尝试使用普通选择器,如本文所建议
const text = Selector('.my-form > a').innerText;
const inner = await text.textContent;
console.log(inner);
// prints: undefined
Run Code Online (Sandbox Code Playgroud)
如何从元素中提取文本?我了解t.selectText在这种情况下会受到限制,对吧?
如果文件上传时间超过 1 分钟,我需要检查功能。
为了通过手动测试来检查它,我使用 Chrome 开发工具来设置节流“慢 3G”。但我不知道如何使用 TestCafe 做到这一点。
在我的testcafe测试中,我需要获取我正在使用的库的构造函数,以便对其调用静态方法。
但是,我无法使用给定的ClientFunction和Eval方法来执行此操作。我该如何获取构造函数?
我尝试了以下方法:
// Does not work, because the docs say it only allows using ClientFunction for obtaining "serializable" values
let getSortable = new ClientFunction(() => window.Sortable);
test('test', async t => {
let Sortable = await getSortable();
console.log(Sortable); // Logs undefined
});
Run Code Online (Sandbox Code Playgroud)
test('test', async t => {
let Sortable = await t.eval(() => window.Sortable);
console.log(Sortable); // Logs undefined (not sure why)
});
Run Code Online (Sandbox Code Playgroud) 测试之间的浏览器始终以干净的状态打开。登录在我的应用程序中被记住,因为身份验证仍然存在,但由于浏览器始终以干净的状态打开,我必须在所有夹具的 Before 挂钩中执行登录。有什么方法可以打开浏览器以便记住用户设置、缓存、本地和会话存储吗?
我正在尝试测试两个不同的控制器类,因为我想测试两个类中的一个方法,并且我将使用 @WebMvcTest,我的问题是有没有办法将模拟注入两个类,可能是这样的?
@WebMvcTest(HomeController.class , BookController.class)
public class ControllerTest{
Run Code Online (Sandbox Code Playgroud)
当然这会导致错误,所以这是否意味着在使用 @WebMvcTest 时我们只能测试一个控制器中的方法?每班
这是不一致的行为,我在 Jenkins 和 GitLab-runner 上都得到了随机结果。在同一台构建机器上运行失败的测试时,一切顺利。(例如,由自动化服务器运行时失败的测试,手动运行时通过 - 使用test.only)
使用 Firefox 和 Chrome 尝试大部分无头,但同样的随机性也发生在完整的 UI 中。
首先,我认为由于并发任务,构建机器上存在资源问题,但我通过安排每晚构建排除了这个问题。此外,我什至将速度降低到 0.8。
有没有其他人遇到过这种行为?任何提示将不胜感激。
web-testing ×10
e2e-testing ×7
testcafe ×7
javascript ×4
testing ×3
java ×2
browser ×1
web-crawler ×1