I am writing Jasmine. I want that when the response from the site is ok (site uploaded- pending 200).
Run the it’s (test cases) in spec and when the site is failed to load the site the it’s (test cases) will not run.
I check the response from site in before all function.
And now in each it that make different thing I check the condition if the response (saved in global var) is true
How can I do it in global fun like before each?
JavaScript
x
39
39
1
let response;
2
3
describe('', ()=>{
4
5
beforeAll (async () => {
6
7
//this function return the statusCode of http request
8
response= await sendQuery('Http://...');
9
})
10
11
beforeEach(async(), =>{
12
});
13
14
15
it('', async()=> {
16
if (response = 200){
17
//do somsing 1...
18
}
19
it('', async()=> {
20
if (response = 200){
21
//do somsing 2...
22
}
23
it('', async()=> {
24
if (response = 200){
25
//do somsing 3...
26
}
27
v
28
it('', async()=> {
29
if (response = 200){
30
//do somsing 4...
31
}
32
it('', async()=> {
33
if (response = 200){
34
//do somsing 5...
35
}
36
it('', async()=> {
37
if (response = 200){
38
//do somsing 6...
39
}
Advertisement
Answer
something like this in your config
JavaScript
1
10
10
1
async onPrepare() {
2
3
global.response = await sendQuery('Http://...');
4
if (global.response !== 200) {
5
throw new Error(`Status is ${response}`); // may not be needed actually, but I'll leave it
6
await browser.close();
7
await process.exit(1);
8
}
9
}
10
global.response
will be available in your specs