简体   繁体   English

Flutter 集成测试:如何等待元素消失并指定超时

[英]Flutter Integration Test: How to wait until element is disappear with specific time out

I am writing a Flutter Integration Test and I'm looking for a code which that allows the automated test to run and proceed after the Login (check step below) finishes automatically.我正在编写一个 Flutter 集成测试,我正在寻找一个代码,它允许自动测试在登录(下面的检查步骤)自动完成后运行和继续。 ..... ......

here are the step involves这是涉及的步骤

  1. Enter username and password输入用户名和密码
  2. hit login button点击登录按钮
  3. then the loading modal will show up for 2 mins // at this step I need to find some code to make sure that the modal is disappeared so that it can proceed to the next step.然后加载模式将显示 2 分钟 // 在这一步我需要找到一些代码以确保模式消失,以便它可以继续下一步。

It's just like Wait Until Element Does Not Contain in Selenium就像Wait Until Element Does Not ContainSelenium

here is my code这是我的代码

  await tester.pumpAndSettle();
  await Future.delayed(const Duration(seconds: 4));
  await tester.pumpAndSettle();
  
  var textBoxForPhone = find.byKey(const Key('txtbPhone'));
  var textBoxForPass = find.byKey(const Key('txtbPass'));
  var btnLogin = find.byKey(const Key('btnLogin'));

  var syncMasterModal = find.byKey(const Key('syncMasterModal'));

// Input Username
  await tester.enterText(textBoxForPhone, '9108717875');
// Input Password
  await tester.enterText(textBoxForPass, '12345');
  await tester.testTextInput.receiveAction(TextInputAction.done);
  await tester.pumpAndSettle();
// Tap Login button
  await tester.tap(btnLogin);

//After tapping the login button the loading modal will appear and it takes about 2 minutes to finish this process
// So it is at this step where I need the code to detect whether the loading modal is disappear 
  

So could you guys help point me in the right direction?那么你们能帮我指出正确的方向吗?

PS. PS。 This is my first time here and English is not my first language so, I'm sorry if my text here is a bit confusing.这是我第一次来这里,英语不是我的第一语言,所以如果我在这里的文字有点混乱,我很抱歉。

after -> await tester.tap(btnLogin);之后 -> 等待 tester.tap(btnLogin); try to add the following lines尝试添加以下行

await tester.pumpAndSettle();等待 tester.pumpAndSettle();
await tester.pumpAndSettle(const Duration(minutes: 2));等待 tester.pumpAndSettle(const Duration(minutes: 2)); // hardcode it if you are sure about the needed time // 如果您确定所需的时间,则对其进行硬编码

expect(find.byType(YourModalWidget), findsNothing);期望(find.byType(YourModalWidget),findNothing);
continue with other code...继续其他代码...

Tip: in your tests, when you are transitioning from one screen to the next, after the first pumpAndSettle() add another with a Duration of around 1 second, or 200/500 milliseconds (depends on what you are expecting to load, and tap after that).提示:在您的测试中,当您从一个屏幕转换到下一个屏幕时,在第一个 pumpAndSettle() 之后添加另一个 Duration 大约为 1 秒或 200/500 毫秒(取决于您期望加载的内容,然后点击在那之后)。 This will make the transition much smoother and it won't look like it is frozen.这将使过渡更加平滑,并且看起来不会像冻结一样。 if you only add pumpAndSettle(const Duration(seconds: 1)), without the first pumpAndSettle() before it, it looks like it's frozen and then the next action in your tests starts.如果您只添加 pumpAndSettle(const Duration(seconds: 1)),而没有在它之前添加第一个 pumpAndSettle(),那么它看起来像是被冻结了,然后您的测试中的下一个动作开始了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM