Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
super-appium
Project
Project
Details
Activity
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
open-source
super-appium
Commits
05a741a1
Commit
05a741a1
authored
Aug 26, 2019
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ea999f41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
3 deletions
+50
-3
SuperAppiumDumper.java
...c/main/java/com/virjar/superappium/SuperAppiumDumper.java
+50
-3
No files found.
super-appium/src/main/java/com/virjar/superappium/SuperAppiumDumper.java
View file @
05a741a1
...
...
@@ -5,13 +5,16 @@ import android.util.Xml;
import
com.virjar.superappium.util.Constants
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.xmlpull.v1.XmlSerializer
;
import
java.io.IOException
;
import
java.io.StringWriter
;
public
class
SuperAppiumDumper
{
public
static
String
dumpTo
String
(
ViewModel
viewModel
)
{
public
static
String
dumpTo
Xml
(
ViewModel
viewModel
)
{
try
{
XmlSerializer
serializer
=
Xml
.
newSerializer
();
StringWriter
stringWriter
=
new
StringWriter
();
...
...
@@ -30,8 +33,12 @@ public class SuperAppiumDumper {
}
private
static
void
dumpNodeRec
(
ViewModel
node
,
XmlSerializer
serializer
)
throws
IOException
{
serializer
.
startTag
(
""
,
"node"
);
String
tag
=
String
.
valueOf
(
node
.
attribute
(
Constants
.
className
));
serializer
.
startTag
(
""
,
tag
);
for
(
String
attrKey
:
node
.
attributeKeys
())
{
if
(
attrKey
.
equals
(
Constants
.
className
))
{
continue
;
}
Object
value
=
node
.
attribute
(
attrKey
);
if
(
value
==
null
)
{
continue
;
...
...
@@ -49,6 +56,46 @@ public class SuperAppiumDumper {
i
,
count
,
node
.
toString
()));
}
}
serializer
.
endTag
(
""
,
"node"
);
serializer
.
endTag
(
""
,
tag
);
}
public
static
String
dumpToJson
(
ViewModel
viewModel
)
{
JSONObject
jsonObject
=
new
JSONObject
();
dumpNodeRec
(
viewModel
,
jsonObject
);
return
jsonObject
.
toString
();
}
private
static
void
dumpNodeRec
(
ViewModel
node
,
JSONObject
container
)
{
for
(
String
attrKey
:
node
.
attributeKeys
())
{
Object
value
=
node
.
attribute
(
attrKey
);
if
(
value
==
null
)
{
continue
;
}
try
{
container
.
putOpt
(
attrKey
,
value
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
int
count
=
node
.
childCount
();
if
(
count
<=
0
)
{
return
;
}
JSONArray
jsonArray
=
new
JSONArray
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
ViewModel
child
=
node
.
childAt
(
i
);
if
(
child
==
null
)
{
jsonArray
.
put
((
Object
)
null
);
}
else
{
JSONObject
childContainer
=
new
JSONObject
();
dumpNodeRec
(
child
,
childContainer
);
jsonArray
.
put
(
childContainer
);
}
}
try
{
container
.
put
(
"children"
,
jsonArray
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
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