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
6408f71a
Commit
6408f71a
authored
Jan 16, 2020
by
Xavjer
Committed by
Jenn Magder
Jan 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Flutter Driver] Extend getText to support more widgets (#48809)
parent
a752435f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
3 deletions
+94
-3
AUTHORS
AUTHORS
+1
-0
extension.dart
packages/flutter_driver/lib/src/extension/extension.dart
+24
-3
extension_test.dart
...es/flutter_driver/test/src/real_tests/extension_test.dart
+69
-0
No files found.
AUTHORS
View file @
6408f71a
...
...
@@ -50,3 +50,4 @@ Jefferson Quesado <jeff.quesado@gmail.com>
Mark Diener <rpzrpzrpz@gmail.com>
Alek Åström <alek.astrom@gmail.com>
Efthymios Sarpmpanis <e.sarbanis@gmail.com>
Cédric Wyss <cedi.wyss@gmail.com>
packages/flutter_driver/lib/src/extension/extension.dart
View file @
6408f71a
...
...
@@ -545,9 +545,30 @@ class FlutterDriverExtension {
Future
<
GetTextResult
>
_getText
(
Command
command
)
async
{
final
GetText
getTextCommand
=
command
as
GetText
;
final
Finder
target
=
await
_waitForElement
(
_createFinder
(
getTextCommand
.
finder
));
// TODO(yjbanov): support more ways to read text
final
Text
text
=
target
.
evaluate
().
single
.
widget
as
Text
;
return
GetTextResult
(
text
.
data
);
final
Widget
widget
=
target
.
evaluate
().
single
.
widget
;
String
text
;
if
(
widget
.
runtimeType
==
Text
)
{
text
=
(
widget
as
Text
).
data
;
}
else
if
(
widget
.
runtimeType
==
RichText
)
{
final
RichText
richText
=
widget
as
RichText
;
if
(
richText
.
text
.
runtimeType
==
TextSpan
)
{
text
=
(
richText
.
text
as
TextSpan
).
text
;
}
}
else
if
(
widget
.
runtimeType
==
TextField
)
{
text
=
(
widget
as
TextField
).
controller
.
text
;
}
else
if
(
widget
.
runtimeType
==
TextFormField
)
{
text
=
(
widget
as
TextFormField
).
controller
.
text
;
}
else
if
(
widget
.
runtimeType
==
EditableText
)
{
text
=
(
widget
as
EditableText
).
controller
.
text
;
}
if
(
text
==
null
)
{
throw
UnsupportedError
(
'Type
${widget.runtimeType.toString()}
is currently not supported by getText'
);
}
return
GetTextResult
(
text
);
}
Future
<
SetTextEntryEmulationResult
>
_setTextEntryEmulation
(
Command
command
)
async
{
...
...
packages/flutter_driver/test/src/real_tests/extension_test.dart
View file @
6408f71a
...
...
@@ -543,6 +543,75 @@ void main() {
expect
(
await
getOffset
(
OffsetType
.
center
),
const
Offset
(
40
+
(
100
/
2
),
30
+
(
120
/
2
)));
});
testWidgets
(
'getText'
,
(
WidgetTester
tester
)
async
{
await
silenceDriverLogger
(()
async
{
final
FlutterDriverExtension
extension
=
FlutterDriverExtension
((
String
arg
)
async
=>
''
,
true
);
Future
<
String
>
getTextInternal
(
SerializableFinder
search
)
async
{
final
Map
<
String
,
String
>
arguments
=
GetText
(
search
,
timeout:
const
Duration
(
seconds:
1
)).
serialize
();
final
Map
<
String
,
dynamic
>
result
=
await
extension
.
call
(
arguments
);
if
(
result
[
'isError'
]
as
bool
)
{
return
null
;
}
return
GetTextResult
.
fromJson
(
result
[
'response'
]
as
Map
<
String
,
dynamic
>).
text
;
}
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Column
(
key:
const
ValueKey
<
String
>(
'column'
),
children:
<
Widget
>[
const
Text
(
'Hello1'
,
key:
ValueKey
<
String
>(
'text1'
)),
Container
(
height:
25.0
,
child:
RichText
(
key:
const
ValueKey
<
String
>(
'text2'
),
text:
const
TextSpan
(
text:
'Hello2'
)
)
),
Container
(
height:
25.0
,
child:
EditableText
(
key:
const
ValueKey
<
String
>(
'text3'
),
controller:
TextEditingController
(
text:
'Hello3'
),
focusNode:
FocusNode
(),
style:
const
TextStyle
(),
cursorColor:
Colors
.
red
,
backgroundCursorColor:
Colors
.
black
)
),
Container
(
height:
25.0
,
child:
TextField
(
key:
const
ValueKey
<
String
>(
'text4'
),
controller:
TextEditingController
(
text:
'Hello4'
)
)
),
Container
(
height:
25.0
,
child:
TextFormField
(
key:
const
ValueKey
<
String
>(
'text5'
),
controller:
TextEditingController
(
text:
'Hello5'
)
)
),
],
))
)
);
expect
(
await
getTextInternal
(
ByValueKey
(
'text1'
)),
'Hello1'
);
expect
(
await
getTextInternal
(
ByValueKey
(
'text2'
)),
'Hello2'
);
expect
(
await
getTextInternal
(
ByValueKey
(
'text3'
)),
'Hello3'
);
expect
(
await
getTextInternal
(
ByValueKey
(
'text4'
)),
'Hello4'
);
expect
(
await
getTextInternal
(
ByValueKey
(
'text5'
)),
'Hello5'
);
// Check if error thrown for other types
final
Map
<
String
,
String
>
arguments
=
GetText
(
ByValueKey
(
'column'
),
timeout:
const
Duration
(
seconds:
1
)).
serialize
();
final
Map
<
String
,
dynamic
>
response
=
await
extension
.
call
(
arguments
);
expect
(
response
[
'isError'
],
true
);
expect
(
response
[
'response'
],
contains
(
'is currently not supported by getText'
));
});
});
testWidgets
(
'descendant finder'
,
(
WidgetTester
tester
)
async
{
await
silenceDriverLogger
(()
async
{
final
FlutterDriverExtension
extension
=
FlutterDriverExtension
((
String
arg
)
async
=>
''
,
true
);
...
...
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