Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
IOTClient
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lola
IOTClient
Commits
a97da2ea
Commit
a97da2ea
authored
May 10, 2019
by
DESKTOP-NFGF3PG\zxa01
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update test
parent
69a4f4b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
174 additions
and
0 deletions
+174
-0
app/build.gradle
app/build.gradle
+7
-0
app/src/androidTest/java/com/example/zxa01/iotclient/component/login/IOTClientTest.java
...xample/zxa01/iotclient/component/login/IOTClientTest.java
+167
-0
No files found.
app/build.gradle
View file @
a97da2ea
...
...
@@ -46,5 +46,12 @@ dependencies {
// retrofit2
implementation
"com.squareup.retrofit2:retrofit:2.1.0"
implementation
"com.squareup.retrofit2:converter-gson:2.1.0"
androidTestImplementation
'com.android.support.test:rules:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-contrib:3.0.2'
,
{
exclude
group:
'com.android.support'
,
module:
'support-annotations'
exclude
group:
'com.android.support'
,
module:
'support-v4'
exclude
group:
'com.android.support'
,
module:
'design'
exclude
group:
'com.android.support'
,
module:
'recyclerview-v7'
}
}
app/src/androidTest/java/com/example/zxa01/iotclient/component/login/IOTClientTest.java
0 → 100644
View file @
a97da2ea
package
com.example.zxa01.iotclient.component.login
;
import
android.support.test.espresso.ViewInteraction
;
import
android.support.test.filters.LargeTest
;
import
android.support.test.rule.ActivityTestRule
;
import
android.support.test.runner.AndroidJUnit4
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewParent
;
import
com.example.zxa01.iotclient.R
;
import
org.hamcrest.Description
;
import
org.hamcrest.Matcher
;
import
org.hamcrest.TypeSafeMatcher
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
android
.
support
.
test
.
espresso
.
Espresso
.
onView
;
import
static
android
.
support
.
test
.
espresso
.
action
.
ViewActions
.
click
;
import
static
android
.
support
.
test
.
espresso
.
action
.
ViewActions
.
scrollTo
;
import
static
android
.
support
.
test
.
espresso
.
contrib
.
RecyclerViewActions
.
actionOnItemAtPosition
;
import
static
android
.
support
.
test
.
espresso
.
matcher
.
ViewMatchers
.
isDisplayed
;
import
static
android
.
support
.
test
.
espresso
.
matcher
.
ViewMatchers
.
withClassName
;
import
static
android
.
support
.
test
.
espresso
.
matcher
.
ViewMatchers
.
withContentDescription
;
import
static
android
.
support
.
test
.
espresso
.
matcher
.
ViewMatchers
.
withId
;
import
static
android
.
support
.
test
.
espresso
.
matcher
.
ViewMatchers
.
withText
;
import
static
org
.
hamcrest
.
Matchers
.
allOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
@LargeTest
@RunWith
(
AndroidJUnit4
.
class
)
public
class
IOTClientTest
{
@Rule
public
ActivityTestRule
<
LoginActivity
>
mActivityTestRule
=
new
ActivityTestRule
<>(
LoginActivity
.
class
);
private
static
Matcher
<
View
>
childAtPosition
(
final
Matcher
<
View
>
parentMatcher
,
final
int
position
)
{
return
new
TypeSafeMatcher
<
View
>()
{
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"Child at position "
+
position
+
" in parent "
);
parentMatcher
.
describeTo
(
description
);
}
@Override
public
boolean
matchesSafely
(
View
view
)
{
ViewParent
parent
=
view
.
getParent
();
return
parent
instanceof
ViewGroup
&&
parentMatcher
.
matches
(
parent
)
&&
view
.
equals
(((
ViewGroup
)
parent
).
getChildAt
(
position
));
}
};
}
@Test
public
void
iOTClientTest
()
{
ViewInteraction
appCompatButton
=
onView
(
allOf
(
withId
(
R
.
id
.
sign_in_button
),
withText
(
"登入"
),
childAtPosition
(
childAtPosition
(
withClassName
(
is
(
"android.widget.ScrollView"
)),
0
),
4
)));
appCompatButton
.
perform
(
scrollTo
(),
click
());
ViewInteraction
floatingActionButton
=
onView
(
allOf
(
withId
(
R
.
id
.
fab
),
childAtPosition
(
childAtPosition
(
withId
(
R
.
id
.
home_fragment_layout
),
0
),
2
),
isDisplayed
()));
floatingActionButton
.
perform
(
click
());
ViewInteraction
appCompatButton2
=
onView
(
allOf
(
withId
(
android
.
R
.
id
.
button2
),
withText
(
"返回"
),
childAtPosition
(
childAtPosition
(
withClassName
(
is
(
"android.widget.ScrollView"
)),
0
),
2
)));
appCompatButton2
.
perform
(
scrollTo
(),
click
());
ViewInteraction
recyclerView
=
onView
(
allOf
(
withId
(
R
.
id
.
device_recycler_view
),
childAtPosition
(
withClassName
(
is
(
"android.widget.FrameLayout"
)),
0
)));
recyclerView
.
perform
(
actionOnItemAtPosition
(
0
,
click
()));
ViewInteraction
appCompatButton3
=
onView
(
allOf
(
withId
(
R
.
id
.
buttonPrivacy
),
withText
(
"隱私選項設定"
),
childAtPosition
(
childAtPosition
(
withClassName
(
is
(
"android.widget.TableRow"
)),
0
),
1
),
isDisplayed
()));
appCompatButton3
.
perform
(
click
());
ViewInteraction
switch_
=
onView
(
allOf
(
withId
(
R
.
id
.
switch1
),
withText
(
"拒絕/同意"
),
childAtPosition
(
childAtPosition
(
withClassName
(
is
(
"android.widget.LinearLayout"
)),
0
),
1
),
isDisplayed
()));
switch_
.
perform
(
click
());
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try
{
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
ViewInteraction
appCompatImageButton
=
onView
(
allOf
(
withContentDescription
(
"向上瀏覽"
),
childAtPosition
(
allOf
(
withId
(
R
.
id
.
action_bar
),
childAtPosition
(
withId
(
R
.
id
.
action_bar_container
),
0
)),
1
),
isDisplayed
()));
appCompatImageButton
.
perform
(
click
());
ViewInteraction
appCompatImageButton2
=
onView
(
allOf
(
withContentDescription
(
"向上瀏覽"
),
childAtPosition
(
allOf
(
withId
(
R
.
id
.
action_bar
),
childAtPosition
(
withId
(
R
.
id
.
action_bar_container
),
0
)),
1
),
isDisplayed
()));
appCompatImageButton2
.
perform
(
click
());
ViewInteraction
bottomNavigationItemView
=
onView
(
allOf
(
withId
(
R
.
id
.
navigation_setting
),
withContentDescription
(
"Setting"
),
childAtPosition
(
childAtPosition
(
withId
(
R
.
id
.
navigation
),
0
),
2
),
isDisplayed
()));
bottomNavigationItemView
.
perform
(
click
());
ViewInteraction
bottomNavigationItemView2
=
onView
(
allOf
(
withId
(
R
.
id
.
navigation_privacy
),
withContentDescription
(
"Record"
),
childAtPosition
(
childAtPosition
(
withId
(
R
.
id
.
navigation
),
0
),
1
),
isDisplayed
()));
bottomNavigationItemView2
.
perform
(
click
());
}
}
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