Component Testing: Simulating user action (DRAFT) 4.0

Send feedback
If you notice any issues with this page, please report them.


Use the method to simulate a user click on a given PO element. Here is an example for a back button:

toh-5/test/hero_detail_po.dart (back button)

@ByTagName('button') PageLoaderElement _button; /* . . . */ Future back() =>;

Similarly, you might define a PO method for selecting a hero from a list as follows:

toh-2/test/app_po.dart (selectHero)

@ByTagName('li') List<PageLoaderElement> _heroes; /* . . . */ Future selectHero(int index) => _heroes[index].click();

Input: add text

The Hero Editor allows a user to edit a hero’s name by means of an <input> element. Use the PageLoaderElement.type() method to simulate adding text to the input element:

toh-1/test/app_test.dart (AppPO input)

class AppPO { /* . . . */ @ByTagName('input') PageLoaderElement _input; /* . . . */ Future type(String s) => _input.type(s); }

Here is an example of how the type() method might be used to update a hero’s name:

toh-1/test/app_test.dart (update name)

const nameSuffix = 'X'; test('update hero name', () async { await appPO.type(nameSuffix); expect(await appPO.heroId, windstormData['id']); expect(await appPO.heroName, windstormData['name'] + nameSuffix); });

Input: clear

You can clear an input using the PageLoaderElement.clear() method:

toh-2/test/app_po.dart (clear)

Future clear() => _input.clear();

Here is an example of a PO method for adding a new hero. It makes use of both clear() and type():

toh-6/test/heroes_po.dart (addHero)

Future<Null> addHero(String name) async { await _input.clear(); await _input.type(name); return; }