com.deque.axe.android.AxeResult.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axe-devtools-android-core Show documentation
Show all versions of axe-devtools-android-core Show documentation
The Axe Devtools Android Core Library
The newest version!
package com.deque.axe.android
import com.deque.axe.android.constants.AxeStatus
import com.deque.axe.android.moshi.MoshiConfig
import com.deque.networking.AxeLogger
import java.io.File
import java.io.IOException
import java.util.LinkedList
class AxeResult @JvmOverloads constructor(
@JvmField val axeConf: AxeConf?,
@JvmField val axeContext: AxeContext?,
@JvmField val axeRuleResults: MutableList? = LinkedList(),
@JvmField var scanName: String? = "",
@JvmField var tags: Set? = setOf()
) {
fun add(axeRuleResult: AxeRuleResult) {
if (axeRuleResult.status != AxeStatus.INAPPLICABLE) {
axeRuleResults?.add(axeRuleResult)
}
}
/**
* Query the list of Rule Results for a particular subset of results.
* @param filter The matcher to filter on.
* @return The list of results that match the filter.
*/
fun query(filter: AxeRuleResult.Matcher): List {
// Micro optimization. Init with size / 2. Results will always be larger than the filtered set.
val results = ArrayList(
axeRuleResults?.let { it.size / 2 } ?: 0
)
axeRuleResults?.let {
for (ruleResult in axeRuleResults) {
if (filter.matches(ruleResult)) {
results.add(ruleResult)
}
}
}
return results
}
fun saveResult(path: File, prefix: String): String? {
try {
val dir = File(path, "AxeTestCases").also { it.mkdirs() }
val file = File(dir, "$prefix-${System.currentTimeMillis()}-axe-result.json")
file.appendText(MoshiConfig.prettyPrint(this, AxeResult::class.java))
AxeLogger.axeResultSavedAt(file.absolutePath)
return file.absolutePath
} catch (exception: IOException) {
AxeLogger.errorWhileSaving(exception)
}
return null
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy