/
How to test for invalid links and images on Confluence pages

How to test for invalid links and images on Confluence pages

 

 

Test Script

unknown.gant
/* * Test to look for unknown image attachments and unresolved internal page links for all pages in all spaces on a site * * gant -f unknown.gant -Dverbose -Dcli="atlassian confluence" -Dclean */ @GrabResolver(name='atlassian', root='https://maven.atlassian.com/content/groups/public/') @Grab(group='org.swift.tools', module='gint', version='1.8.2') import org.swift.tools.* includeTool << org.swift.tools.Helper // helper utilities includeTool << org.swift.tools.GintForConfluence // gint framework with extensions for Confluence testing gint.initialize(this) // required def info = gint.getServerInfoWithVerify() // verify server is available, otherwise end test def cmdGen = gint.getCmdGenerator() // get default command generator - this will handle the cli command parameter // Get a list of all spaces - products a csv file def fileName = gint.getOutputFile('spacelist.csv') def cmd = cmdGen.call(action: 'getSpaceList', file: fileName) helper.runCmd(cmd: cmd) // Read the file into a list of rows, each row is a map to access the column data - space data in this case def mapList = helper.convertRowListToMapList(helper.csvDataAsListOfRows(fileName: fileName)) //helper.logWithFormat('mapList', mapList) def spaces = [] // list of spaces mapList.each { map -> spaces.add(map.Key) // For testing, might just want to set spaces to a specific list //spaces = ['recipes'] // list of space keys helper.logWithFormat('spaces', spaces) errorFile = new File(gint.getOutputFile('unknownErrors.csv')) // simple log of each page with a broken link errorFile.write('"Space","Title","Reason"\n') helper.logWithFormat('errorFile', errorFile.getAbsolutePath()) // for each space, get a list of pages and create a testcase for each page spaces.each { space -> fileName = gint.getOutputFile(space + '-pagelist.csv') cmd = cmdGen.call( action: 'getPageList', parameters: [space: space, outputFormat: 2], // format 2 to get a csv list file: fileName, ) helper.runCmd(cmd: cmd) // Read the file into a list of rows, each row is a map to access the column data - page data in this case mapList = helper.convertRowListToMapList(helper.csvDataAsListOfRows(fileName: fileName)) mapList.each { map -> gint.add( name: space + '-' + map.Title.replace(' ', '+'), action: 'render', // render the page file: true, // result goes to the standard file parameters: [ id: map.Id, // use page id to identify the page clean: null, // don't need styling ], output: [ failData: [ 'placeholder/unknown-attachment', // missing attachment like: src="/wiki/plugins/servlet/confluence/placeholder/unknown-attachment 'class="unresolved"', // missing link like: <a class="unresolved" href="#">missing-link</a> ], ], finalClosure: { testcase -> helper.logWithFormat('testcase', testcase) if (testcase.success == false) { errorFile << /"${space}",${helper.quoteString(map.Title, '"')},${helper.quoteString(testcase.failReason, '"')}/ << '\n' } } ) } } gint.finalizeTest() // final preparations for running tests

© 2005 -2024 gint.org