Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
74f6fa45
Unverified
Commit
74f6fa45
authored
Oct 08, 2020
by
Marcin Jeleński
Committed by
GitHub
Oct 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flutter Driver - Create widget finders from serialized finders extensions (#67456)
parent
cb0bdb49
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
357 additions
and
150 deletions
+357
-150
create_finder_factory.dart
.../flutter_driver/lib/src/common/create_finder_factory.dart
+115
-0
find.dart
packages/flutter_driver/lib/src/common/find.dart
+1
-1
extension.dart
packages/flutter_driver/lib/src/extension/extension.dart
+35
-105
extension_test.dart
...es/flutter_driver/test/src/real_tests/extension_test.dart
+149
-44
stub_finder.dart
...flutter_driver/test/src/real_tests/stubs/stub_finder.dart
+19
-0
stub_finder_extension.dart
...iver/test/src/real_tests/stubs/stub_finder_extension.dart
+38
-0
No files found.
packages/flutter_driver/lib/src/common/create_finder_factory.dart
0 → 100644
View file @
74f6fa45
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'find.dart'
;
/// A factory which creates [Finder]s from [SerializableFinder]s.
mixin
CreateFinderFactory
{
/// Creates the flutter widget finder from [SerializableFinder].
Finder
createFinder
(
SerializableFinder
finder
)
{
switch
(
finder
.
finderType
)
{
case
'ByText'
:
return
_createByTextFinder
(
finder
as
ByText
);
case
'ByTooltipMessage'
:
return
_createByTooltipMessageFinder
(
finder
as
ByTooltipMessage
);
case
'BySemanticsLabel'
:
return
_createBySemanticsLabelFinder
(
finder
as
BySemanticsLabel
);
case
'ByValueKey'
:
return
_createByValueKeyFinder
(
finder
as
ByValueKey
);
case
'ByType'
:
return
_createByTypeFinder
(
finder
as
ByType
);
case
'PageBack'
:
return
_createPageBackFinder
();
case
'Ancestor'
:
return
_createAncestorFinder
(
finder
as
Ancestor
);
case
'Descendant'
:
return
_createDescendantFinder
(
finder
as
Descendant
);
default
:
return
null
;
}
}
Finder
_createByTextFinder
(
ByText
arguments
)
{
return
find
.
text
(
arguments
.
text
);
}
Finder
_createByTooltipMessageFinder
(
ByTooltipMessage
arguments
)
{
return
find
.
byElementPredicate
((
Element
element
)
{
final
Widget
widget
=
element
.
widget
;
if
(
widget
is
Tooltip
)
{
return
widget
.
message
==
arguments
.
text
;
}
return
false
;
},
description:
'widget with text tooltip "
${arguments.text}
"'
);
}
Finder
_createBySemanticsLabelFinder
(
BySemanticsLabel
arguments
)
{
return
find
.
byElementPredicate
((
Element
element
)
{
if
(
element
is
!
RenderObjectElement
)
{
return
false
;
}
final
String
semanticsLabel
=
element
.
renderObject
?.
debugSemantics
?.
label
;
if
(
semanticsLabel
==
null
)
{
return
false
;
}
final
Pattern
label
=
arguments
.
label
;
return
label
is
RegExp
?
label
.
hasMatch
(
semanticsLabel
)
:
label
==
semanticsLabel
;
},
description:
'widget with semantic label "
${arguments.label}
"'
);
}
Finder
_createByValueKeyFinder
(
ByValueKey
arguments
)
{
switch
(
arguments
.
keyValueType
)
{
case
'int'
:
return
find
.
byKey
(
ValueKey
<
int
>(
arguments
.
keyValue
as
int
));
case
'String'
:
return
find
.
byKey
(
ValueKey
<
String
>(
arguments
.
keyValue
as
String
));
default
:
throw
'Unsupported ByValueKey type:
${arguments.keyValueType}
'
;
}
}
Finder
_createByTypeFinder
(
ByType
arguments
)
{
return
find
.
byElementPredicate
((
Element
element
)
{
return
element
.
widget
.
runtimeType
.
toString
()
==
arguments
.
type
;
},
description:
'widget with runtimeType "
${arguments.type}
"'
);
}
Finder
_createPageBackFinder
()
{
return
find
.
byElementPredicate
((
Element
element
)
{
final
Widget
widget
=
element
.
widget
;
if
(
widget
is
Tooltip
)
{
return
widget
.
message
==
'Back'
;
}
if
(
widget
is
CupertinoNavigationBarBackButton
)
{
return
true
;
}
return
false
;
},
description:
'Material or Cupertino back button'
);
}
Finder
_createAncestorFinder
(
Ancestor
arguments
)
{
final
Finder
finder
=
find
.
ancestor
(
of:
createFinder
(
arguments
.
of
),
matching:
createFinder
(
arguments
.
matching
),
matchRoot:
arguments
.
matchRoot
,
);
return
arguments
.
firstMatchOnly
?
finder
.
first
:
finder
;
}
Finder
_createDescendantFinder
(
Descendant
arguments
)
{
final
Finder
finder
=
find
.
descendant
(
of:
createFinder
(
arguments
.
of
),
matching:
createFinder
(
arguments
.
matching
),
matchRoot:
arguments
.
matchRoot
,
);
return
arguments
.
firstMatchOnly
?
finder
.
first
:
finder
;
}
}
packages/flutter_driver/lib/src/common/find.dart
View file @
74f6fa45
...
...
@@ -24,7 +24,7 @@ mixin DeserializeFinderFactory {
case
'Descendant'
:
return
Descendant
.
deserialize
(
json
,
this
);
case
'Ancestor'
:
return
Ancestor
.
deserialize
(
json
,
this
);
}
throw
DriverError
(
'Unsupported search specification type
$finderType
'
)
;
return
null
;
}
}
...
...
packages/flutter_driver/lib/src/extension/extension.dart
View file @
74f6fa45
This diff is collapsed.
Click to expand it.
packages/flutter_driver/test/src/real_tests/extension_test.dart
View file @
74f6fa45
This diff is collapsed.
Click to expand it.
packages/flutter_driver/test/src/real_tests/stubs/stub_finder.dart
0 → 100644
View file @
74f6fa45
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_driver/flutter_driver.dart'
;
class
StubFinder
extends
SerializableFinder
{
StubFinder
(
this
.
keyString
);
final
String
keyString
;
@override
String
get
finderType
=>
'Stub'
;
@override
Map
<
String
,
String
>
serialize
()
{
return
super
.
serialize
()..
addAll
(<
String
,
String
>{
'keyString'
:
keyString
});
}
}
packages/flutter_driver/test/src/real_tests/stubs/stub_finder_extension.dart
0 → 100644
View file @
74f6fa45
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/src/widgets/framework.dart'
;
import
'package:flutter_driver/driver_extension.dart'
;
import
'package:flutter_driver/src/common/create_finder_factory.dart'
;
import
'package:flutter_test/src/finders.dart'
;
import
'package:flutter_driver/src/common/find.dart'
;
import
'stub_finder.dart'
;
class
StubFinderExtension
extends
FinderExtension
{
@override
Finder
createFinder
(
SerializableFinder
finder
,
CreateFinderFactory
finderFactory
,
)
{
return
find
.
byWidgetPredicate
((
Widget
widget
)
{
final
Key
key
=
widget
.
key
;
if
(
key
is
!
ValueKey
<
String
>)
{
return
false
;
}
return
(
key
as
ValueKey
<
String
>).
value
==
(
finder
as
StubFinder
).
keyString
;
});
}
@override
SerializableFinder
deserialize
(
Map
<
String
,
String
>
params
,
DeserializeFinderFactory
finderFactory
,
)
{
return
StubFinder
(
params
[
'keyString'
]);
}
@override
String
get
finderType
=>
'Stub'
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment