Skip to content

Commit 00325c4

Browse files
committed
update tests to use localhost
1 parent 4bd8e85 commit 00325c4

6 files changed

Lines changed: 34 additions & 12 deletions

File tree

lib/helper/WebDriver.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,12 @@ class WebDriver extends Helper {
721721
*
722722
*/
723723
amOnPage(url) {
724+
let split_url;
724725
if (this.config.basicAuth) {
725-
const split_url = url.split('//');
726+
if (url.startsWith('/')) {
727+
url = this.config.url + url;
728+
}
729+
split_url = url.split('//');
726730
url = `${split_url[0]}//${this.config.basicAuth.username}:${this.config.basicAuth.password}@${split_url[1]}`;
727731
}
728732
return this.browser.url(url);

test/data/app/controllers.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,10 @@ function GET()
282282
readfile($file_url); //Absolute URL
283283
exit();
284284
}
285+
}
286+
287+
class basic_auth {
288+
function GET() {
289+
include __DIR__.'/view/basic_auth.php';
290+
}
285291
}

test/data/app/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'/dynamic' => 'dynamic',
4343
'/timeout' => 'timeout',
4444
'/download' => 'download',
45+
'/basic_auth' => 'basic_auth'
4546
);
4647

4748
glue::stick($urls);

test/data/app/view/basic_auth.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
if (!isset($_SERVER['PHP_AUTH_USER'])) {
3+
header('WWW-Authenticate: Basic realm="My Realm"');
4+
header('HTTP/1.0 401 Unauthorized');
5+
echo 'Text to send if user hits Cancel button';
6+
exit;
7+
} else {
8+
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
9+
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
10+
}
11+
?>

test/helper/Puppeteer_test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Puppeteer - BasicAuth', () => {
1919
global.codecept_dir = path.join(__dirname, '/../data');
2020

2121
I = new Puppeteer({
22-
url: 'https://postman-echo.com',
22+
url: 'http://localhost:8000',
2323
windowSize: '500x700',
2424
show: false,
2525
waitForTimeout: 5000,
@@ -28,7 +28,7 @@ describe('Puppeteer - BasicAuth', () => {
2828
args: ['--no-sandbox', '--disable-setuid-sandbox'],
2929
},
3030
defaultPopupAction: 'accept',
31-
basicAuth: { username: 'postman', password: 'password' },
31+
basicAuth: { username: 'admin', password: 'admin' },
3232
});
3333
I._init();
3434
return I._beforeSuite();
@@ -50,8 +50,8 @@ describe('Puppeteer - BasicAuth', () => {
5050

5151
describe('open page with provided basic auth', () => {
5252
it('should be authenticated ', async () => {
53-
await I.amOnPage('/basic-auth');
54-
await I.see('{"authenticated":true}');
53+
await I.amOnPage('/basic_auth');
54+
await I.see('You entered admin as your password.');
5555
});
5656
});
5757
});
@@ -111,8 +111,8 @@ describe('Puppeteer', function () {
111111
});
112112

113113
it('should be unauthenticated ', async () => {
114-
await I.amOnPage('https://postman-echo.com/basic-auth');
115-
await I.see('Unauthorized');
114+
await I.amOnPage('/basic_auth');
115+
await I.dontSee('You entered admin as your password.');
116116
});
117117
});
118118

test/helper/WebDriver_test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ describe('WebDriver - Basic Authentication', () => {
10661066

10671067
wd = new WebDriver({
10681068
url: siteUrl,
1069-
basicAuth: { username: 'postman', password: 'password' },
1069+
basicAuth: { username: 'admin', password: 'admin' },
10701070
browser: 'chrome',
10711071
windowSize: '500x700',
10721072
remoteFileUpload: true,
@@ -1082,17 +1082,17 @@ describe('WebDriver - Basic Authentication', () => {
10821082
});
10831083
});
10841084

1085-
beforeEach(() => {
1085+
beforeEach(async () => {
10861086
webApiTests.init({ I: wd, siteUrl });
1087-
return wd._before();
1087+
await wd._before();
10881088
});
10891089

10901090
afterEach(() => wd._after());
10911091

10921092
describe('open page : #amOnPage', () => {
10931093
it('should be authenticated', async () => {
1094-
await wd.amOnPage('https://postman-echo.com/basic-auth');
1095-
await wd.see('{"authenticated":true}');
1094+
await wd.amOnPage('/basic_auth');
1095+
await wd.see('You entered admin as your password.');
10961096
});
10971097
});
10981098
});

0 commit comments

Comments
 (0)