Code Monkey home page Code Monkey logo

pageloader's Introduction

PageLoader

Build Status

A framework for creating page objects for in-browser tests or Webdriver tests.

For a beginner's guide, refer to our quickstart guide.

For in-depth explanation of PageLoader's anatomy and features, refer to our anatomy section.

Refer to our best practices section to master using PageLoader.

Starting with version 3.0.0, PageLoader is changed significantly from version 2.X.X. Refer to our what changed section for more information.

How do I trigger the generation step?

dart run build_runner build

If you are starting with a fresh checkout or deleted your .dart_tool directory, pass the flag: --delete-conflicting-outputs.

WARNING: Your PageObject Dart files must be within test/... subdirectory

pageloader's People

Contributors

blackhc avatar chalin avatar dramos07 avatar drmarcii avatar elvisun avatar goderbauer avatar har79 avatar hpoit avatar jacob314 avatar juliemr avatar kevmoo avatar liuming0 avatar mgreenland avatar mk13 avatar natebosch avatar scheglov avatar srawlins avatar staats-google avatar stereotype441 avatar tacocat avatar thuemler avatar vsmenon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pageloader's Issues

Handle material-dropdown-select behavior

Hi, I need to simulate a selection of an item on a material dropdown select
How I can do this?

I tried this but it does not seem to work:

  /// material-dropdown-select
  @First(ById('zonage'))
  PageLoaderElement get zonage;
  
  @ByTagName('material-select-dropdown-item')
  List<PageLoaderElement> get items;

/// In the test
  test('enable zone on zonage selection', () async {
    await po.zonage.click();
    await po.items[2].click(); // index out of range error
  });

Update minimal environment

Since 3.1.0 the pageloader package can't be used with dart 2.1.0 beacuse of the usage of the new set feature.

Save generated files to build output folder not the original source folder

From #130 (comment):

The pageloader-builder-generated *.g.dart files get written to the original source folder. Can we ensure that they are instead saved where ever the Angular *.template.dart files are saved (which includes the build output folder when it is specified)?

Maybe this has to do with the use of part of "foo.g.dart". That is another thing that Angular is able to avoid. It is a lot more convenient to be able to import "foo.g.dart" as bar to avoid errors from tools even when the .g.dart file isn't present.

cc @natebosch @kwalrath

Consider `import` of generated PO files rather than use of `part` statements

For both site-www and site-webdev, we'd like to continue running the analyzer on example sources before attempting to build a package. We can't do that anymore with the current pageloader scheme since missing part files are reported as errors (unless we also commit generated files, which I prefer not doing).

As was mentioned in #132, use of import allows us to benefit from the analyzer's ability to ignore uri_has_not_been_generated issues. Could we switch to using import, or at least have that option, for pageloader?

(I've created this separate issue because #132 is covering a different, though related, issue.)

cc @kevmoo @mk13 @natebosch @kwalrath

Release 3.0.0-beta

Any there specific items we should validate before we release?

Sanity check w/ @chalin ?

CC @mk13

Let's make sure to discuss before we do this...

Building package:pageloader throws InconsistentAnalysisException

Repro:

  1. clone repository
  2. pub get
  3. pub run build_runner build --delete-conflicting-outputs

Expcetion:

[SEVERE] pageloader:pageloader on test/examples/correct/list.dart (cached):

InconsistentAnalysisException: Requested result might be inconsistent with previously returned results

package:analyzer/src/dart/analysis/session.dart 202:7                   AnalysisSessionImpl._checkConsistency
package:analyzer/src/dart/analysis/session.dart 169:5                   AnalysisSessionImpl.getResolvedLibraryByElement
package:pageloader/src/generators/pageobject_generator.dart 39:31       PageObjectGenerator.generateForAnnotatedElement
package:source_gen/src/generator_for_annotation.dart 53:30              GeneratorForAnnotation.generate
package:source_gen/src/builder.dart 303:33                              _generate
package:source_gen/src/builder.dart 79:15                               _Builder._generateForLibrary
package:source_gen/src/builder.dart 71:11                               _Builder.build
package:build                                                           runBuilder
package:build_runner_core/src/generate/build_impl.dart 485:19           _SingleBuild._runForInput.<fn>.<fn>.<fn>
package:build_runner_core/src/generate/performance_tracker.dart 302:15  _NoOpBuilderActionTracker.trackStage
package:build_runner_core/src/generate/build_impl.dart 483:23           _SingleBuild._runForInput.<fn>.<fn>
package:build_runner_core/src/generate/build_impl.dart                  _SingleBuild._runForInput.<fn>.<fn>
package:timing/src/timing.dart 222:44                                   NoOpTimeTracker.track
package:build_runner_core/src/generate/build_impl.dart 440:22           _SingleBuild._runForInput.<fn>
package:pool/pool.dart 127:28                                           Pool.withResource
package:build_runner_core/src/generate/build_impl.dart 436:17           _SingleBuild._runForInput
package:build_runner_core/src/generate/build_impl.dart 374:38           _SingleBuild._runBuilder.<fn>
dart:async                                                              Future.wait
package:build_runner_core/src/generate/build_impl.dart 373:36           _SingleBuild._runBuilder
package:build_runner_core/src/generate/build_impl.dart 319:20           _SingleBuild._runPhases.<fn>.<fn>
dart:async                                                              _completeOnAsyncReturn
package:build_runner_core/src/generate/build_impl.dart                  _SingleBuild._matchingPrimaryInputs

Dart SDK version: 2.10.4 (stable) (Wed Nov 11 13:35:58 2020 +0100) on "linux_x64"

Link manual from README

There is a PageLoaderManual.md file in repository which contains a useful description of a library, however, it's at the moment unnecessary hard to find. It would be great if it would be linked from README.md (or even inlined there)

Documentation for modifying chrome args to load custom profiles or extensions.

Please include documentation for how to modify chrome arguments to load chrome profiles or extensions.

At the moment I am really struggling with the lack of web driver and selenium to deal with basic authentication now that URL encoding is unsupported.

How and in what format can I add necessary parameters such as:
–start-maximized
--user-data-dir=pathToUserProfile
–load-extension=pathToChromeExtension

into the below from pageloader/dart/async/test/setup/webdriver_test_setup.dart:

if (env['CHROMEDRIVER_ARGS'] != null) {
chromeOptions['args'] = env['CHROMEDRIVER_ARGS'].split(' ');
}

Non-null safe Angular 6 compatibility

Could we have a version of this library that is compatible with Angular 6? Would be also nice if we could opt out of null-safe attempts until it is more mature.

Follow up on webdriver changes

This ticket is a reminder for self.

There are upcoming changes to webdriver to support Firefox again. It's not fully complete in the external version. This will cause changes to WebdriverPageLoaderElement that needs to be synced up with.

This will likely mean a new version of webdriver will also be released, in which we would have to sync with.

PageLoaderElement shouldn't return Streams

PageLoaderElement#classes is of type Stream<String>. This seems pointless. It's not like you really expect that you will have to wait a while to get the 1st class and then wait more to get the 2nd, etc. More realistic is that you will have to wait a little for the UI to stabilize and then get all the classes at once, i.e. it should be Future<List<String>> (or maybe Future<Iterable<String>> but prefer the former). Streams are a bit harder to work with than Futures, e.g.

var classes = foo.classes;
expect(await classes.contains('foo'), true);
// Fails.  Oops, we exhausted the stream.  Not a problem with lists.
expect(await classes.contains('foo'), true);

This line of code shows that even the implementation has access to a normal Iterable:

Stream<String> get classes => new Stream.fromIterable(node.classes);

PageLoaderElement#getElementsByCss seems to have a similar pointlessly-hard-to-use return type.

PageLoaderElement.exists throws on removed element when using with WebDriver

Using PageLoader with WebDriver on Windows x64, dart 2.7.2, pageloader 3.3.0, chromedriver 80.0.3987.106

Having the following PO snippet:

@ByCss("button.i-am-here-when-the-page-loads")
PageLoaderElement get initiallyPresentButton;

Future<void> trigger() async {
  if (initiallyPresentButton.exists) {
    await initiallyPresentButton.click();
  }
}

and

  1. calling trigger() in the above block,
  2. removing the button from DOM
  3. and calling trigger() again
    will throw
Unhandled exception:
StaleElementReferenceException (404): stale element reference: element is not attached to the page document
  (Session info: chrome=80.0.3987.149)
#0      parseW3cResponse (package:webdriver/src/handler/w3c/utils.dart:82:9)
#1      W3cElementFinder.parseFindElementsResponse (package:webdriver/src/handler/w3c/element_finder.dart:45:13) #2      SyncRequestClient.send (package:webdriver/src/common/request_client.dart:46:25)
#3      WebElement.findElements (package:webdriver/src/sync/web_element.dart:135:25)
#4      WebDriverPageLoaderElement.elements (package:pageloader/src/webdriver/webdriver_page_loader_element.dart:179:12)
#5      WebDriverPageLoaderElement.exists (package:pageloader/src/webdriver/webdriver_page_loader_element.dart:270:19)

Seems like the exists getter is not wrapped in retryWhenStale(), causing exception on removed elements.

Version solving failed

Working dir: /Users/xxx/WebstormProjects/toh-5-master
/usr/local/Cellar/dart/2.3.2/libexec/bin/pub get
Resolving dependencies...
Because pageloader >=3.0.0 depends on build_config ^0.3.1 and build_runner >=1.3.4 depends on build_config >=0.4.0 <0.4.1, pageloader >=3.0.0 is incompatible with build_runner >=1.3.4.
So, because angular_tour_of_heroes depends on both build_runner ^1.5.0 and pageloader ^3.0.0, version solving failed.
Process finished with exit code 1

Add analyzer 0.40.0 support

type and isObject are deprecated as of analyzer 0.40.0, this causes build issues in cases where analyzer >=0.40.0 <0.40.7 is needed in the same project as pageloader.

They should be replaced with thisType and isDartCoreObject respectively.

Upgrade to source_gen ^0.8.0

Pageloader at HEAD is using source_gen ^0.7.0.

I'm eager to upgrade Angular example app tests to the new pageloader, but Angular is already using source_gen ^0.8.0. (There may be other issues, but this seemed like the first hurdle.)

cc @kwalrath @kevmoo

ElementPageLoader always returns null for "name" attribute

If I have an element like:

<div name="some descriptive name">

and then try to access its "name" attribute:

var name = await element.attributes['name'];

I get back null instead of the actual name.

It looks like the library does correctly grab the value out of the attribute here, but then clobbers it with null later on.

It looks like the actual element has a name field, even though it doesn't show up when drilling down into the thing with devtools.

Divide async and sync dart version into two separate packages

I would like to separate the dart version of pageloader into two separate pub packages: One for sync and the other for the async version (similar to how async and sync webdriver.dart is separate).

Advantages:

  • cleaner dependencies (async pageloader doesn't need to depend on sync webdriver)
  • easier to deprecate sync pageloader when it is a separate package
  • versions for async and sync can increase independently

I would suggest keeping both versions in this github repository. I would just change the directory structure from dart/lib/async and dart/lib/sync to dart/async/lib and dart/sync/lib. The same change would be applied to the other directories (test, etc).

@DrMarcII Any objections?

innerText vs visibleText

The docs for innerText and visibleText aren't very helpful. They state what implementation the text should come from but that, for both, "behaviour may vary". They don't state how it varies, what the purpose of each is, or how they differ.

Is there a reason to ever prefer one over the other? Can one be deprecated?

Additionally, the innerText docs have a few issues:

  • "text content" is confusing as this is different from the HTML textContent attribute
  • the link is broken

Upcoming strong-mode errors

Latest analyzer includes new strong mode errors that should be addressed:

$ ~/code/dart-repo3/sdk/xcodebuild/ReleaseX64/dart-sdk/bin/dartanalyzer --strong lib/
Analyzing [lib/]...
[warning] Unsound implicit cast from dynamic to List<Node> (/Users/srawlins/code/dart-pageloader/dart/async/lib/html.dart, line 167, col 21)
[warning] Unsound implicit cast from Future<dynamic> to Future<T> (/Users/srawlins/code/dart-pageloader/dart/async/lib/src/core.dart, line 88, col 23)
[warning] Unsound implicit cast from Future<dynamic> to Future<T> (/Users/srawlins/code/dart-pageloader/dart/async/lib/src/core.dart, line 88, col 23)
[error] Could not infer type parameter T, dynamic must be of type num. (/Users/srawlins/code/dart-pageloader/dart/async/lib/webdriver.dart, line 261, col 16)
[error] Could not infer type parameter T, dynamic must be of type num. (/Users/srawlins/code/dart-pageloader/dart/async/lib/webdriver.dart, line 275, col 16)
[warning] Unsound implicit cast from Future<dynamic> to Future<T> (/Users/srawlins/code/dart-pageloader/dart/async/lib/src/core.dart, line 88, col 23)
[warning] Unsound implicit cast from Future<dynamic> to Future<String> (/Users/srawlins/code/dart-pageloader/dart/async/lib/webdriver.dart, line 385, col 46)
[warning] Unsound implicit cast from Future<dynamic> to Future<String> (/Users/srawlins/code/dart-pageloader/dart/async/lib/webdriver.dart, line 396, col 46)
2 errors and 6 warnings found.

Provide concrete examples for creating a PO

From the README:

Construction of these PageObjects are easy; call the 'create' constructor
and pass in the context. You want the <html> node for tests.

 final myPO = new MyPO.create(pageLoaderElementContext);

It may be "easy" to create POs, but there should be at least one concrete example of how to do so. I'm not sure, but I think that the following should work:

  Element htmlElement = ...;
  final context = new HtmlPageLoaderElement.createFromElement(htmlElement);
  final myPO = new MyPO.create(context);

Is the above correct? If so, I don't mind submitting a PR.

It might also be a good idea to explain when it is a good idea to provide a SyncFn (an example of that would be nice too).

cc @kevmoo @kwalrath

pageloader conflicts with build_runner

Hi!
When i try to use angulardart projects like here, all goes well until pageloader was adding.

Say, this works well:

dev_dependencies:
  angular_test: ^2.3.0
  build_runner: ^1.5.0
  build_test: ^0.10.7
  build_web_compilers: ^2.1.0
  test: ^1.6.3

but this

dev_dependencies:
  angular_test: ^2.3.0
  build_runner: ^1.5.0
  build_test: ^0.10.7
  build_web_compilers: ^2.1.0
  pageloader: ^3.0.0
  test: ^1.6.3

generates error:

Because build_runner >=1.3.4 depends on build_config >=0.4.0 <0.4.1 and pageloader >=3.0.0 depends on build_config ^0.3.1, build_runner >=1.3.4 is incompatible with pageloader >=3.0.0.
So, because angular_tour_of_heroes depends on both pageloader ^3.0.0 and build_runner ^1.5.0, version solving failed.

As one sees the problem is in build_config cross clashing, and no focuses with changing versions are working.

OS: Ubuntu 18.04

Running 'pub run build_runner build' throws error: 'Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.'

Running 'pub run build_runner build' on the pageloader throws error: 'Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.'

According to the Readme this is the correct way to run this project.
I have been trying with different version of the Dart SDK: 2.10.3, 2.9.3, 2.8.1, and 2.7.0.
But everytime I run this, I get following error:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] lib/src/generators/methods/core_method_information.dart:23:6: Error: Error when reading 'lib/src/generators/methods/core_method_information.g.dart': No such file or directorypart 'core_method_information.g.dart';     ^lib/src/generators/methods/getter.dart:23:6: Error: Error when reading 'lib/src/generators/methods/getter.g.dart': No such file or directorypart 'getter.g.dart';     ^lib/src/generators/methods/iterable_finder_method.dart:25:6: Error: Error when reading 'lib/src/generators/methods/iterable_finder_method.g.dart': No such file or directorypart 'iterable_finder_method.g.dart';     ^lib/src/generators/methods/list_finder_method.dart:25:6: Error: Error when reading 'lib/src/generators/methods/list_finder_method.g.dart': No such file or directorypart 'list_finder_method.g.dart';     ^lib/src/generators/methods/mouse_finder_method.dart:25:6: Error: Error when reading 'lib/src/generators/methods/mouse_finder_method.g.dart': No such file or directorypart 'mouse_finder_method.g.dart';     ^lib/src/generators/methods/pointer_finder_method.dart:25:6: Error: Error when reading 'lib/src/generators/methods/pointer_finder_method.g.dart': No such file or directorypart 'pointer_finder_method.g.dart';     ^lib/src/generators/methods/setter.dart:22:6: Error: Error when reading 'lib/src/generators/methods/setter.g.dart': No such file or directorypart 'setter.g.dart';     ^lib/src/generators/methods/single_finder_method.dart:26:6: Error: Error when reading 'lib/src/generators/methods/single_finder_method.g.dart': No such file or directorypart 'single_finder_method.g.dart';     ^lib/src/generators/methods/unannotated_method.dart:22:6: Error: Error when reading 'lib/src/generators/methods/unannotated_method.g.dart': No such file or directorypart 'unannotated_method.g.dart';     ^lib/src/generators/methods/core_method_information.dart:23:6: Error: Can't use 'lib/src/generators/methods/core_method_information.g.dart' as a part, because it has no 'part of' declaration.part 'core_method_information.g.dart';     ^

Steps to Reproduce

  • checkout the pageloader repository
  • run 'pub get'
  • run 'pub run build_runner build'

The reason I would like to run this project, is to find out why my AngularDart tests have been failing lately.
I think it might be because this project is outdated (and presumably not maintained anymore).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.