forked from getgauge/taiko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincognito.test.js
200 lines (172 loc) · 5.93 KB
/
incognito.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
const expect = require('chai').expect;
let {
openBrowser,
closeBrowser,
switchTo,
text,
goto,
openTab,
closeTab,
setConfig,
evaluate,
openIncognitoWindow,
closeIncognitoWindow,
currentURL,
} = require('../../lib/taiko');
let { openBrowserArgs, resetConfig } = require('./test-util');
let { createHtml, removeFile } = require('./test-util');
describe('Browser Context', () => {
let url1, url2;
before(async () => {
await openBrowser(openBrowserArgs);
setConfig({
waitForNavigation: true,
retryTimeout: 10,
retryInterval: 10,
});
const innerHtml = `<section class="header">
<h1>Incognito tests</h1>
</section>
<section class='main-content'>
<div class='item'>
Item 1
</div>
<div class='item'>
Browser1
</div>
</section>`;
const innerHtml1 = `<section class="header">
<h1>Incognitotests</h1>
</section>
<section class='main-content'>
<div class='item'>
Item 2
</div>
<div class='item'>
Browser2
</div>
</section>`;
url1 = createHtml(innerHtml, 'Incognito');
url2 = createHtml(innerHtml1, 'Incognito1');
});
after(async () => {
resetConfig();
await closeBrowser();
removeFile(url2);
removeFile(url1);
});
describe('open browser and create browser context', () => {
it('Should have incognito window', async () => {
await openIncognitoWindow(url1, { name: 'admin' });
let actual = await text('Browser1').exists();
expect(actual).to.be.true;
await openIncognitoWindow(url2, { name: 'user' });
let actualBrowser2 = await text('Browser2').exists();
expect(actualBrowser2).to.be.true;
await switchTo({ name: 'admin' });
let backToUser1 = await text('Browser1').exists();
expect(backToUser1).to.be.true;
let browser1 = await evaluate(text('Item 1'), (element) => {
return element.textContent.trim();
});
expect(browser1).to.be.equal('Item 1');
let inactiveUser2 = await text('Browser2').exists();
expect(inactiveUser2).to.be.false;
});
after(async () => {
await closeIncognitoWindow('admin');
await closeIncognitoWindow('user');
});
});
describe('open incognito window without url', () => {
it('should open a blank page when url not given', async () => {
await openIncognitoWindow({ name: 'admin' });
expect(await currentURL()).to.equal('about:blank');
await closeIncognitoWindow('admin');
});
});
describe('Open window in Incognito Mode', () => {
it('Open window in incognito', async () => {
await openIncognitoWindow(url1, { name: 'admin' });
});
after(async () => {
await closeIncognitoWindow('admin');
});
});
describe('Open window in Incognito Mode', () => {
it('Open window in incognito and use the default window', async () => {
await openIncognitoWindow(url1, { name: 'admin' });
await closeIncognitoWindow('admin');
await goto(url1);
let backToDefaultBrowser = await text('Browser1').exists();
expect(backToDefaultBrowser).to.be.true;
});
});
describe('Open window with same window name', () => {
it('Should throw error if window name is not unique', async () => {
await openIncognitoWindow(url1, { name: 'admin' });
try {
await openIncognitoWindow(url1, { name: 'admin' });
} catch (err) {
expect(err.message).to.be.equal(
'There is a already a window/tab with name admin. Please use another name',
);
}
});
after(async () => {
await closeIncognitoWindow('admin');
});
});
describe('Isolation session storage test', () => {
it('should isolate localStorage and cookies', async () => {
await openIncognitoWindow(url1, { name: 'admin' });
await evaluate(() => {
localStorage.setItem('name', 'page1');
});
await openIncognitoWindow(url2, { name: 'user' });
await evaluate(() => {
localStorage.setItem('name', 'page2');
});
const adminSessionLocalStorage = await evaluate(() => {
return localStorage.getItem('name');
});
expect(adminSessionLocalStorage).to.equal('page2');
await switchTo({ name: 'admin' });
const userSessionLocalStorage = await evaluate(() => {
return localStorage.getItem('name');
});
expect(userSessionLocalStorage).to.equal('page1');
});
after(async () => {
await closeIncognitoWindow('admin');
await closeIncognitoWindow('user');
});
});
describe('open window throws an error', () => {
it('openIncognitoWindow should throw an error when url parameter is missing', async () => {
await openIncognitoWindow({ name: 'window' }).catch((error) =>
expect(error).to.be.an.instanceOf(TypeError),
);
});
it('openIncognitoWindow should throw an error when window name parameter is missing', async () => {
await openIncognitoWindow('localhost:8000').catch((error) =>
expect(error).to.be.an.instanceOf(TypeError),
);
});
});
describe('close incognito window', () => {
it('closeIncognitoWindow should not throw error when the target used to get context id is closed', async () => {
let exceptionThrown = false;
try {
await openIncognitoWindow({ name: 'admin' });
await goto(url1);
await openTab(url2);
await closeTab(url1);
await closeIncognitoWindow('admin');
} catch {
exceptionThrown = true;
}
expect(exceptionThrown).to.be.false;
});
});
});