File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,21 @@ class FileSystem extends Helper {
59
59
assert . ok ( fileExists ( this . file ) , `File ${ name } not found in ${ this . dir } ` ) ;
60
60
}
61
61
62
+ /**
63
+ * Checks that file with a name including given text exists in the current directory.
64
+ *
65
+ *```js
66
+ * I.handleDownloads();
67
+ * I.click('Download as PDF');
68
+ * I.amInPath('output/downloads');
69
+ * I.seeFileNameMatching('.pdf');
70
+ * ```
71
+ */
72
+ seeFileNameMatching ( text ) {
73
+ assert . ok ( this . grabFileNames ( ) . some ( file => file . includes ( text ) ) ,
74
+ `File name which contains ${ text } not found in ${ this . dir } ` ) ;
75
+ }
76
+
62
77
/**
63
78
* Checks that file found by `seeFile` includes a text.
64
79
* @param {string } text
@@ -98,6 +113,21 @@ class FileSystem extends Helper {
98
113
const content = getFileContents ( this . file , encoding ) ;
99
114
fileEquals ( this . file ) . negate ( text , content ) ;
100
115
}
116
+
117
+ /**
118
+ * Returns file names in current directory.
119
+ *
120
+ * ```js
121
+ * I.handleDownloads();
122
+ * I.click('Download Files');
123
+ * I.amInPath('output/downloads');
124
+ * const downloadedFileNames = I.grabFileNames();
125
+ * ```
126
+ */
127
+ grabFileNames ( ) {
128
+ return fs . readdirSync ( this . dir )
129
+ . filter ( item => ! fs . lstatSync ( path . join ( this . dir , item ) ) . isDirectory ( ) ) ;
130
+ }
101
131
}
102
132
103
133
function getFileContents ( file , encoding ) {
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ describe('FileSystem', () => {
22
22
fs . dir . should . eql ( path . join ( global . codecept_dir , '/data' ) ) ;
23
23
} ) ;
24
24
25
+ it ( 'should see file' , ( ) => {
26
+ fs . seeFile ( 'data/fs_sample.txt' ) ;
27
+ fs . amInPath ( 'data' ) ;
28
+ fs . seeFile ( 'fs_sample.txt' ) ;
29
+ fs . grabFileNames ( ) . should . contain ( 'fs_sample.txt' ) ;
30
+ fs . seeFileNameMatching ( 'sample' ) ;
31
+ } ) ;
32
+
25
33
it ( 'should check file contents' , ( ) => {
26
34
fs . seeFile ( 'data/fs_sample.txt' ) ;
27
35
fs . seeInThisFile ( 'FileSystem' ) ;
You can’t perform that action at this time.
0 commit comments