Skip to content

Commit

Permalink
fix showCancel
Browse files Browse the repository at this point in the history
  • Loading branch information
seveniruby committed Oct 28, 2017
1 parent 9c9cd0f commit b8a2909
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 88 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,10 @@
# 2.1.1[TODO]
# 2.2.0 [TODO]
- 支持从历史数据中寻找最优点击路径
- 支持web
- 支持游戏app遍历
- 使用节点树模型

# 2.1.2
- 跟进支持appium 1.7[完成]

# 2.1.0
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/testerhome/appcrawler/AppCrawler.scala
Expand Up @@ -17,7 +17,8 @@ object AppCrawler extends CommonLog {
val banner=
"""
|----------------
|AppCrawler 2.1.1 [霍格沃兹测试学院特别纪念版]
|AppCrawler 2.1.2 [霍格沃兹测试学院特别纪念版]
|Appium Version 1.7.1 support
|app爬虫, 用于自动遍历测试. 支持Android和iOS, 支持真机和模拟器
|帮助文档: http://seveniruby.gitbooks.io/appcrawler
|移动测试技术交流: https://testerhome.com
Expand Down
18 changes: 8 additions & 10 deletions src/main/scala/com/testerhome/appcrawler/Crawler.scala
Expand Up @@ -210,7 +210,7 @@ class Crawler extends CommonLog {

//爬虫结束
stop()

sys.exit()
}

def restart(): Unit = {
Expand Down Expand Up @@ -355,7 +355,7 @@ class Crawler extends CommonLog {

def needBackApp(): Boolean = {
log.trace(conf.appWhiteList)
log.trace(appNameRecord.record)
log.trace(appNameRecord.last(10))

//跳到了其他app. 排除点一次就没有的弹框
if (conf.appWhiteList.forall(appNameRecord.last().toString.matches(_)==false)) {
Expand Down Expand Up @@ -980,6 +980,8 @@ class Crawler extends CommonLog {
}
case "backApp" => {
driver.launchApp()
//todo: 改进等待
Thread.sleep(8000)
/*if (conf.defaultBackAction.size > 0) {
log.trace(conf.defaultBackAction)
conf.defaultBackAction.foreach(Runtimes.eval)
Expand Down Expand Up @@ -1124,19 +1126,15 @@ class Crawler extends CommonLog {
}
}
log.info("generate report finish")
sys.exit()
}
}

def handleCtrlC(): Unit = {
log.info("add shutdown hook")
Signal.handle(new Signal("INT"), new SignalHandler() {
def handle(sig: Signal) {
log.info("exit by INT")
signalInt += 1
stop()
sys.exit(1)
}
Signal.handle(new Signal("INT"), (sig: Signal) => {
log.info("exit by INT")
signalInt += 1
stop()
})
}
}
154 changes: 85 additions & 69 deletions src/main/scala/com/testerhome/appcrawler/TemplateTestCase.scala
Expand Up @@ -23,91 +23,107 @@ class TemplateTestCase extends FunSuite with BeforeAndAfterAllConfigMap with Mat
.sortBy(_.clickedIndex)

log.info(sortedElements.size)
//把未遍历的放到后面

val selected = if (Report.showCancel) {
sortedElements.filter(_.action == ElementStatus.Clicked) ++ sortedElements.filter(_.action == ElementStatus.Skiped)
log.info("show all elements")
//把未遍历的放到后面
sortedElements.filter(_.action == ElementStatus.Clicked) ++
sortedElements.filter(_.action == ElementStatus.Skipped) ++
sortedElements.filter(_.action == ElementStatus.Ready)
} else {
log.info("only show clicked elements")
sortedElements.filter(_.action == ElementStatus.Clicked)
}
println(selected.size)
log.info(selected.size)
selected.foreach(ele => {
val testcase = ele.element.loc.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "")
.replace("\r", "")

test(s"clickedIndex=${ele.clickedIndex} xpath=${testcase}") {
if (ele.action == ElementStatus.Clicked) {
markup(
s"""
|
//todo: 增加ignore和cancel的区分
test(s"clickedIndex=${ele.clickedIndex} action=${ele.action}\nxpath=${testcase}") {
ele.action match {
case ElementStatus.Clicked => {
markup(
s"""
|
|<img src='${File(ele.reqImg).name}' width='80%' />
|<br></br>
|<p>after clicked</p>
|<img src='${File(ele.resImg).name}' width='80%' />
""".stripMargin
)

/*
markup(
s"""
|
|<pre>
|<xmp>
|${ele.reqDom.replaceFirst("xml", "x_m_l")}
|</xmp>
|</pre>
|<br></br>
|<p>after clicked</p>
|<img src='${File(ele.resImg).name}' width='80%' />
""".stripMargin
)
*/
val req = XPathUtil.toDocument(ele.reqDom)
val res = XPathUtil.toDocument(ele.resDom)
log.debug(ele.reqDom)
AppCrawler.crawler.conf.asserts.foreach(assert => {
val given = assert.getOrElse("given", List[String]()).asInstanceOf[List[String]]
log.info(given.map(g => XPathUtil.getListFromXPath(g, req).size))
if (given.forall(g => XPathUtil.getListFromXPath(g, req).size > 0) == true) {
log.info(s"asserts match")
val existAsserts = assert.getOrElse("then", List[String]()).asInstanceOf[List[String]]
val cp = new scalatest.Checkpoints.Checkpoint
existAsserts.foreach(existAssert => {
log.debug(existAssert)
cp {
withClue(s"${existAssert} 不存在\n") {
XPathUtil.getListFromXPath(existAssert, res).size should be > 0
}
)

/*
markup(
s"""
|
|<pre>
|<xmp>
|${ele.reqDom.replaceFirst("xml", "x_m_l")}
|</xmp>
|</pre>
""".stripMargin
)
*/
val req = XPathUtil.toDocument(ele.reqDom)
val res = XPathUtil.toDocument(ele.resDom)
log.debug(ele.reqDom)
AppCrawler.crawler.conf.asserts.foreach(assert => {
val given = assert.getOrElse("given", List[String]()).asInstanceOf[List[String]]
log.info(given.map(g => XPathUtil.getListFromXPath(g, req).size))
if (given.forall(g => XPathUtil.getListFromXPath(g, req).size > 0) == true) {
log.info(s"asserts match")
val existAsserts = assert.getOrElse("then", List[String]()).asInstanceOf[List[String]]
val cp = new scalatest.Checkpoints.Checkpoint
existAsserts.foreach(existAssert => {
log.debug(existAssert)
cp {
withClue(s"${existAssert} 不存在\n") {
XPathUtil.getListFromXPath(existAssert, res).size should be > 0
}
}
})
cp.reportAll()
} else {
log.info("not match")
}
})
cp.reportAll()
} else {
log.info("not match")
}
})

AppCrawler.crawler.conf.testcase.steps.foreach(step => {
if (XPathUtil.getListFromXPath(step.when.xpath, req)
.map(_.getOrElse("xpath", ""))
.headOption == Some(ele.element.loc)
) {
log.info(s"match testcase ${ele.element.loc}")

if(step.then!=null) {
val cp = new scalatest.Checkpoints.Checkpoint
step.then.foreach(existAssert => {
log.debug(existAssert)
cp {
withClue(s"${existAssert} 不存在\n") {
XPathUtil.getListFromXPath(existAssert, res).size should be > 0
}

AppCrawler.crawler.conf.testcase.steps.foreach(step => {
if (XPathUtil.getListFromXPath(step.when.xpath, req)
.map(_.getOrElse("xpath", ""))
.headOption == Some(ele.element.loc)
) {
log.info(s"match testcase ${ele.element.loc}")

if(step.then!=null) {
val cp = new scalatest.Checkpoints.Checkpoint
step.then.foreach(existAssert => {
log.debug(existAssert)
cp {
withClue(s"${existAssert} 不存在\n") {
XPathUtil.getListFromXPath(existAssert, res).size should be > 0
}
}
})
cp.reportAll()
}
})
cp.reportAll()
}
} else {
log.info("not match")
}
})
} else {
log.info("not match")
}
})

}
case ElementStatus.Ready => {
cancel(s"${ele.action} not click")
}
case ElementStatus.Skipped => {
cancel(s"${ele.action} skipped")
}
}

}
})
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ class URIElementStore {
elementStore(element.toString)=ElementInfo()
elementStore(element.toString).element=element
}
elementStore(element.toString).action=ElementStatus.Skiped
elementStore(element.toString).action=ElementStatus.Skipped
}

def setElementClicked(element: URIElement): Unit = {
Expand Down Expand Up @@ -121,7 +121,7 @@ class URIElementStore {

def isSkiped(ele: URIElement): Boolean = {
if (elementStore.contains(ele.toString)) {
elementStore(ele.toString).action == ElementStatus.Skiped
elementStore(ele.toString).action == ElementStatus.Skipped
} else {
AppCrawler.log.trace(s"element=${ele.toLoc()} first show, need click")
false
Expand All @@ -132,7 +132,7 @@ class URIElementStore {
}

object ElementStatus extends Enumeration {
val Ready, Clicked, Skiped = Value
val Ready, Clicked, Skipped = Value
}

case class ElementInfo(
Expand Down
Expand Up @@ -40,7 +40,7 @@ class TestDataObject extends FunSuite with CommonLog with Matchers{
}

test("json to yaml"){
val conf=new CrawlerConf().load("src/test/scala/com/xueqiu/qa/appcrawler/it/xueqiu_private.json")
val conf=new CrawlerConf().load("src/test/scala/com/xueqiu/qa/appcrawler/it/xueqiu_private.yml")
log.info(conf)
val yaml=DataObject.toYaml(conf)
File("src/test/scala/com/xueqiu/qa/appcrawler/it/xueqiu_private.yml").writeAll(yaml)
Expand All @@ -57,7 +57,7 @@ class TestDataObject extends FunSuite with CommonLog with Matchers{
}

test("read json"){
val conf=DataObject.fromJson[CrawlerConf](Source.fromFile("src/test/scala/com/xueqiu/qa/appcrawler/it/xueqiu_private.json").getLines().mkString("\n"))
val conf=DataObject.fromJson[CrawlerConf](Source.fromFile("src/test/scala/com/xueqiu/qa/appcrawler/it/xueqiu_private.yml").getLines().mkString("\n"))
log.info(conf.saveScreen)
}
test("map yaml"){
Expand Down
Expand Up @@ -14,7 +14,7 @@ class TestElementStore extends FunSuite with Matchers with CommonLog{
val element_1=URIElement("a", "b", "c", "d", "e")
val info_1=new ElementInfo()
info_1.element=element_1
info_1.action=ElementStatus.Skiped
info_1.action=ElementStatus.Skipped


val element_2=URIElement("aa", "bb", "cc", "dd", "ee")
Expand Down
Expand Up @@ -19,7 +19,7 @@ class TestReportPlugin extends FunSuite with CommonLog{
val element_1=URIElement("a", "b", "c", "d", "e")
val info_1=new ElementInfo()
info_1.element=element_1
info_1.action=ElementStatus.Skiped
info_1.action=ElementStatus.Skipped


val element_2=URIElement("aa", "bb", "cc", "dd", "ee")
Expand Down

0 comments on commit b8a2909

Please sign in to comment.