@@ -5,10 +5,11 @@ import { PageUtils } from "../../../utils/page-utils";
55import { Before , After } from "@cucumber/cucumber" ;
66import { StorageUtils } from "../utils/storage" ;
77import { configurations } from "../../../utils/configurations" ;
8- import { rm , testSshConnection } from "../../../utils/commands" ;
8+ import { rm , testSshConnection , uninstallPlugin } from "../../../utils/commands" ;
99import { WP_SSH_ROOT_DIR } from "../../../config/wp.config" ;
1010import { Page } from "@playwright/test" ;
11-
11+ import { BACKWPUP_INFOS } from "../../../config/wp.config" ;
12+ import { getFolderNameFromHost } from "../utils/helpers" ;
1213
1314/**
1415 * Before each test scenario with the @bwpupsetup tag, performs setup tasks.
@@ -26,7 +27,7 @@ Before({tags: '@bwpupsetup'}, async function(this: ICustomWorld, {pickle}) {
2627/**
2728 * After every test, delete data
2829 */
29- After ( async function ( this : ICustomWorld ) {
30+ After ( { tags : '@bwpup or @bwpupsetup' } , async function ( this : ICustomWorld ) {
3031 await deleteAllData ( this . page ) ;
3132 try {
3233 await testSshConnection ( ) ;
@@ -35,16 +36,41 @@ After(async function (this: ICustomWorld) {
3536 await rm ( backwpupFolder ) ;
3637 const backwpupRestoreFolder = `${ WP_SSH_ROOT_DIR } wp-content/uploads/backwpup-restore` ;
3738 await rm ( backwpupRestoreFolder ) ;
39+ // Remove any BackWPup plugin zip files that may have been uploaded during tests.
40+ const backwpupPluginZips = `${ WP_SSH_ROOT_DIR } wp-content/uploads/**/**/backwpup*.zip` ;
41+ await rm ( backwpupPluginZips ) ;
3842
3943 // Remove BackWPup plugin
4044 await this . utils . deactivateBackWpViaUi ( ) ;
4145 await this . utils . removeBackWpViaUi ( ) ;
46+ await uninstallPlugin ( 'show-time' ) ;
4247 } catch ( error ) {
4348 console . error ( 'Setup failed: ' , error . message ) ;
4449 throw new Error ( 'Setup failed: ' + error . message ) ;
4550 }
4651} ) ;
4752
53+ After ( { tags : '@bwpupstorageftp' } , async function ( this : ICustomWorld ) {
54+ // Nothing to do if no SSH access for FTP is set
55+ if ( ! BACKWPUP_INFOS . ftp . sshDirectory || ! BACKWPUP_INFOS . ftp . sshUsername ) return ;
56+ try {
57+ // Clear FTP storage
58+ const sshConfig = {
59+ host : BACKWPUP_INFOS . ftp . host ,
60+ username : BACKWPUP_INFOS . ftp . sshUsername
61+ } ;
62+ await testSshConnection ( { ...sshConfig } ) ;
63+ const directoryName = getFolderNameFromHost ( ) ;
64+ const destination = `${ BACKWPUP_INFOS . ftp . sshDirectory } /${ directoryName } /*` ;
65+ await rm ( destination , {
66+ ...sshConfig
67+ } ) ;
68+ } catch ( error ) {
69+ // Catch error and fail silently, as FTP cleanup is not critical
70+ console . error ( 'FTP Cleanup failed: ' , error . message ) ;
71+ }
72+ } ) ;
73+
4874async function deleteAllData ( page : Page ) : Promise < void > {
4975 const response = await page . goto ( `${ configurations . baseUrl } /wp-admin/admin.php?page=backwpup` ) ;
5076 // We check status, because for some tests, the plugin will be uninstalled before getting here
0 commit comments