Skip to content

Commit 014a488

Browse files
authored
[ci] Start test site the-internet localhost in CI using container (#2998)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent ba7a4e2 commit 014a488

16 files changed

+211
-21
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ release: tag_major_minor release_grid_scaler
679679
docker push $(NAME)/standalone-all-browsers:$(MAJOR_MINOR_PATCH)
680680
docker push $(NAME)/video:$(FFMPEG_TAG_VERSION)-$(BUILD_DATE)
681681

682+
start_test_site:
683+
@docker rm -f the-internet 2>/dev/null || true
684+
@docker run --rm --name the-internet -d -p 5001:5000 ndviet/the-internet:latest
685+
@echo "Test site started at http://localhost:5001"
686+
682687
test: test_chrome \
683688
test_chrome_standalone \
684689
test_chrome_standalone_java \
@@ -839,7 +844,7 @@ test_parallel: hub chrome firefox edge chromium video
839844
echo CHART_CERT_PATH=$$(readlink -f ./videos/certs/tls.crt) >> .env ; \
840845
export $$(cat .env | xargs) ; \
841846
DOCKER_DEFAULT_PLATFORM=$(PLATFORMS) docker compose --profile $(PLATFORMS) -f docker-compose-v3-test-parallel.yml up -d --remove-orphans --no-log-prefix ; \
842-
RUN_IN_DOCKER_COMPOSE=true bash ./bootstrap.sh $$node ; \
847+
RUN_IN_DOCKER_COMPOSE=true TEST_SITE=the-internet:5000 bash ./bootstrap.sh $$node ; \
843848
docker compose -f docker-compose-v3-test-parallel.yml down ; \
844849
done
845850
make test_video_integrity

tests/CDPTests/tests/Tests.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
const {test, expect} = require('@playwright/test');
22
const path = require('path');
33

4+
// Get test site URL from environment variable or use default
5+
const TEST_SITE = process.env.TEST_SITE || 'the-internet.herokuapp.com';
6+
47
function sleep(ms: number) {
58
return new Promise(resolve => setTimeout(resolve, ms));
69
}
710

811
test.describe.parallel('Parallel tests connect to autoscaling Grid', () => {
912
test('test_title', async ({page}) => {
10-
await page.goto('https://the-internet.herokuapp.com');
13+
await page.goto(`http://${TEST_SITE}`);
1114
await expect(page).toHaveTitle('The Internet');
1215
await sleep(2);
1316
});
1417

1518
test('test_with_frames', async ({page}) => {
16-
await page.goto('http://the-internet.herokuapp.com/nested_frames');
19+
await page.goto(`http://${TEST_SITE}/nested_frames`);
1720
const frame = page.frameLocator('frame[name="frame-top"]').frameLocator('frame[name="frame-middle"]');
1821
await expect(frame.locator('#content')).toHaveText('MIDDLE');
1922
await sleep(2);
2023
});
2124

2225
test('test_select_from_a_dropdown', async ({page}) => {
23-
await page.goto('http://the-internet.herokuapp.com/dropdown');
26+
await page.goto(`http://${TEST_SITE}/dropdown`);
2427
const dropdown = await page.locator('#dropdown');
2528
await dropdown.selectOption({label: 'Option 1'});
2629
const selectedOption = await dropdown.inputValue();
@@ -29,14 +32,14 @@ test.describe.parallel('Parallel tests connect to autoscaling Grid', () => {
2932
});
3033

3134
test('test_visit_basic_auth_secured_page', async ({page}) => {
32-
await page.goto('http://admin:admin@the-internet.herokuapp.com/basic_auth');
35+
await page.goto(`http://admin:admin@${TEST_SITE}/basic_auth`);
3336
const pageMessage = await page.locator('.example p').textContent();
3437
expect(pageMessage.trim()).toBe('Congratulations! You must have the proper credentials.');
3538
await sleep(2);
3639
});
3740

3841
test('test_download_file', async ({page}) => {
39-
await page.goto('https://the-internet.herokuapp.com/download');
42+
await page.goto(`http://${TEST_SITE}/download`);
4043
const fileLink = page.locator('a', {hasText: 'some-file.txt'});
4144
await fileLink.scrollIntoViewIfNeeded();
4245
const [download] = await Promise.all([

tests/SeleniumJavaTests/bootstrap_java.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ VERSION="${VERSION:-"latest"}"
1010
function cleanup {
1111
echo "Stopping the Selenium Grid container..."
1212
docker rm -f standalone || true
13+
docker rm -f the-internet || true
14+
docker network rm standalone || true
1315
exit $exit_code
1416
}
1517

@@ -18,7 +20,9 @@ trap cleanup EXIT
1820
# Change to the test directory relative to the project root
1921
cd "$(dirname "$0")"
2022

21-
docker run --rm --name standalone -d -p 4444:4444 "${NAMESPACE}/${IMAGE_NAME}:${VERSION}"
23+
docker network create standalone
24+
docker run --rm --name the-internet -d --network standalone "ndviet/the-internet:latest"
25+
docker run --rm --name standalone -d --network standalone -p 4444:4444 "${NAMESPACE}/${IMAGE_NAME}:${VERSION}"
2226

2327
until curl -s "${GRID_URL}/status" | grep -q 'Selenium Grid ready'; do
2428
echo "Waiting for Selenium Grid to be ready..."
@@ -30,5 +34,6 @@ echo "Running tests with Selenium Grid at ${GRID_URL}"
3034

3135
export GRID_URL="${GRID_URL}"
3236
export BROWSER="${BROWSER}"
37+
export TEST_SITE="the-internet:5000"
3338
./gradlew clean test
3439
exit_code=$?

tests/SeleniumJavaTests/src/test/java/SeleniumTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
class SeleniumTests {
2121
private WebDriver driver;
22+
private String TEST_SITE = System.getenv().getOrDefault("TEST_SITE", "the-internet.herokuapp.com");
2223

2324
@BeforeEach
2425
void setUp() {
@@ -59,15 +60,15 @@ void setUp() {
5960

6061
@Test
6162
void abTestingLinkOpensCorrectPage() {
62-
driver.get("https://the-internet.herokuapp.com/");
63+
driver.get(String.format("http://%s", TEST_SITE));
6364
driver.findElement(By.linkText("A/B Testing")).click();
6465
String header = driver.findElement(By.tagName("h3")).getText();
6566
assert header.contains("A/B Test");
6667
}
6768

6869
@Test
6970
void checkboxesCanBeToggled() {
70-
driver.get("https://the-internet.herokuapp.com/checkboxes");
71+
driver.get(String.format("http://%s/checkboxes", TEST_SITE));
7172
WebElement checkbox1 = driver.findElements(By.cssSelector("input[type='checkbox']")).get(0);
7273
boolean initialState = checkbox1.isSelected();
7374
checkbox1.click();
@@ -76,7 +77,7 @@ void checkboxesCanBeToggled() {
7677

7778
@Test
7879
void dropdownSelectionWorks() {
79-
driver.get("https://the-internet.herokuapp.com/dropdown");
80+
driver.get(String.format("http://%s/dropdown", TEST_SITE));
8081
WebElement dropdown = driver.findElement(By.id("dropdown"));
8182
Select select = new Select(dropdown);
8283
select.selectByVisibleText("Option 2");

tests/SeleniumTests/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
LIST_CHROMIUM_VERSIONS = ['140.0', '139.0', '138.0', '137.0', '136.0', '135.0', '134.0']
4040
LIST_FIREFOX_VERSIONS = ['142.0', '141.0', '140.0', '139.0', '138.0', '137.0', '136.0']
4141
LIST_PLATFORMS = ['Linux', None, 'Windows 11']
42+
TEST_SITE = os.environ.get('TEST_SITE', 'the-internet.herokuapp.com')
4243

4344
if not TEST_MULTIPLE_VERSIONS_EXPLICIT:
4445
LIST_CHROMIUM_VERSIONS.append(None)
@@ -65,15 +66,15 @@
6566
class SeleniumGenericTests(unittest.TestCase):
6667

6768
def test_title(self):
68-
self.driver.get('https://the-internet.herokuapp.com')
69+
self.driver.get(f'http://{TEST_SITE}')
6970
wait = WebDriverWait(self.driver, WEB_DRIVER_WAIT_TIMEOUT)
7071
wait.until(EC.title_is('The Internet'))
7172
self.assertTrue(self.driver.title == 'The Internet')
7273

7374
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/03-work-with-frames/python/frames.py
7475
def test_with_frames(self):
7576
driver = self.driver
76-
driver.get('http://the-internet.herokuapp.com/nested_frames')
77+
driver.get(f'http://{TEST_SITE}/nested_frames')
7778
wait = WebDriverWait(driver, WEB_DRIVER_WAIT_TIMEOUT)
7879
frame_top = wait.until(EC.frame_to_be_available_and_switch_to_it('frame-top'))
7980
frame_middle = wait.until(EC.frame_to_be_available_and_switch_to_it('frame-middle'))
@@ -82,7 +83,7 @@ def test_with_frames(self):
8283
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/05-select-from-a-dropdown/python/dropdown.py
8384
def test_select_from_a_dropdown(self):
8485
driver = self.driver
85-
driver.get('http://the-internet.herokuapp.com/dropdown')
86+
driver.get(f'http://{TEST_SITE}/dropdown')
8687
dropdown_list = driver.find_element(By.ID, 'dropdown')
8788
options = dropdown_list.find_elements(By.TAG_NAME, 'option')
8889
for opt in options:
@@ -98,7 +99,7 @@ def test_select_from_a_dropdown(self):
9899
# https://github.com/tourdedave/elemental-selenium-tips/blob/master/13-work-with-basic-auth/python/basic_auth_1.py
99100
def test_visit_basic_auth_secured_page(self):
100101
driver = self.driver
101-
driver.get('http://admin:admin@the-internet.herokuapp.com/basic_auth')
102+
driver.get(f'http://admin:admin@{TEST_SITE}/basic_auth')
102103
page_message = driver.find_element(By.CSS_SELECTOR, '.example p').text
103104
self.assertTrue(page_message == 'Congratulations! You must have the proper credentials.')
104105

@@ -116,7 +117,7 @@ def test_play_video(self):
116117

117118
def test_download_file(self):
118119
driver = self.driver
119-
driver.get('https://the-internet.herokuapp.com/download')
120+
driver.get(f'http://{TEST_SITE}/download')
120121
file_name = 'some-file.txt'
121122
wait = WebDriverWait(driver, 30)
122123
file_link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, file_name)))
@@ -305,7 +306,7 @@ def setUp(self):
305306
raise e
306307

307308
def test_title_and_maximize_window(self):
308-
self.driver.get('https://the-internet.herokuapp.com')
309+
self.driver.get(f'http://{TEST_SITE}')
309310
self.driver.maximize_window()
310311
self.assertTrue(self.driver.title == 'The Internet')
311312

tests/bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ elif [ "$1" = "AutoScalingTestsScaleChaos" ]; then
2727
python3 -m unittest AutoscalingTests.test_scale_chaos
2828
ret_code=$?
2929
else
30+
export TEST_SITE="the-internet:5000"
3031
python3 test.py $1
3132
ret_code=$?
3233
fi

tests/charts/ci/local-pvc.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ spec:
5656
containers:
5757
- name: ftp-server
5858
image: delfer/alpine-ftp-server:latest
59+
ports:
60+
- name: ftp
61+
containerPort: 21
62+
livenessProbe:
63+
tcpSocket:
64+
port: ftp
65+
initialDelaySeconds: 10
66+
periodSeconds: 5
67+
failureThreshold: 3
68+
timeoutSeconds: 2
69+
readinessProbe:
70+
tcpSocket:
71+
port: ftp
72+
initialDelaySeconds: 5
73+
periodSeconds: 5
74+
failureThreshold: 3
75+
timeoutSeconds: 2
76+
resources:
77+
limits:
78+
cpu: "200m"
79+
memory: "256Mi"
80+
requests:
81+
cpu: "100m"
82+
memory: "128Mi"
5983
env:
6084
- name: USERS
6185
value: "seluser|selenium.dev"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: the-internet
5+
labels:
6+
app: the-internet
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: the-internet
12+
template:
13+
metadata:
14+
labels:
15+
app: the-internet
16+
spec:
17+
containers:
18+
- name: the-internet
19+
image: ndviet/the-internet:latest
20+
imagePullPolicy: IfNotPresent
21+
ports:
22+
- containerPort: 5000
23+
resources:
24+
limits:
25+
cpu: "200m"
26+
memory: "256Mi"
27+
requests:
28+
cpu: "100m"
29+
memory: "64Mi"
30+
livenessProbe:
31+
httpGet:
32+
path: /
33+
port: 5000
34+
initialDelaySeconds: 10
35+
periodSeconds: 10
36+
failureThreshold: 3
37+
readinessProbe:
38+
httpGet:
39+
path: /
40+
port: 5000
41+
initialDelaySeconds: 5
42+
periodSeconds: 5
43+
---
44+
apiVersion: v1
45+
kind: Service
46+
metadata:
47+
name: the-internet
48+
labels:
49+
app: the-internet
50+
spec:
51+
type: ClusterIP
52+
ports:
53+
- port: 5000
54+
targetPort: 5000
55+
protocol: TCP
56+
name: http
57+
selector:
58+
app: the-internet

tests/charts/make/chart_test.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TEST_MULTIPLE_PLATFORMS=${TEST_MULTIPLE_PLATFORMS:-"false"}
7070
TEST_MULTIPLE_PLATFORMS_RELAY=${TEST_MULTIPLE_PLATFORMS_RELAY:-"false"}
7171
TEST_CUSTOM_SPECIFIC_NAME=${TEST_CUSTOM_SPECIFIC_NAME:-"false"}
7272
TEST_VIDEO_RECORDER_SIDECAR=${TEST_VIDEO_RECORDER_SIDECAR:-"false"}
73+
TEST_SITE=${TEST_SITE:-"the-internet:5000"}
7374

7475
wait_for_terminated() {
7576
# Wait until no pods are in "Terminating" state
@@ -164,8 +165,9 @@ if [ "${TEST_UPGRADE_CHART}" != "true" ] && [ "${RENDER_HELM_TEMPLATE_ONLY}" !=
164165
sudo chmod -R 777 ${HOST_PATH}
165166
kubectl create ns ${SELENIUM_NAMESPACE} || true
166167
kubectl apply -n ${SELENIUM_NAMESPACE} -f ${LOCAL_PVC_YAML}
168+
kubectl apply -n ${SELENIUM_NAMESPACE} -f "${TEST_VALUES_PATH}/the-internet-deployment.yaml"
167169
kubectl describe pod,svc,pv,pvc -n ${SELENIUM_NAMESPACE} -l app=ftp-server
168-
kubectl delete pod -n ${SELENIUM_NAMESPACE} -l app=ftp-server --force --grace-period=0
170+
kubectl describe pod,svc,pv,pvc -n ${SELENIUM_NAMESPACE} -l app=the-internet
169171
fi
170172

171173
if [ "${TEST_NAME_OVERRIDE}" = "true" ]; then
@@ -546,6 +548,7 @@ export TEST_MULTIPLE_VERSIONS_EXPLICIT=${TEST_MULTIPLE_VERSIONS_EXPLICIT}
546548
export TEST_MULTIPLE_PLATFORMS=${TEST_MULTIPLE_PLATFORMS}
547549
export TEST_MULTIPLE_PLATFORMS_RELAY=${TEST_MULTIPLE_PLATFORMS_RELAY}
548550
export TEST_CUSTOM_SPECIFIC_NAME=${TEST_CUSTOM_SPECIFIC_NAME}
551+
export TEST_SITE="${TEST_SITE}"
549552
if [ "${MATRIX_BROWSER}" = "NoAutoscaling" ]; then
550553
./tests/bootstrap.sh NodeFirefox
551554
if [ "${TEST_PLATFORMS}" = "linux/amd64" ]; then

tests/docker-compose-v3-test-node-docker.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ services:
5757
- ./videos/upload:/ftp/seluser
5858
stop_grace_period: 30s
5959

60+
the-internet:
61+
image: ndviet/the-internet:latest
62+
container_name: the-internet
63+
6064
tests:
6165
image: docker-selenium-tests:latest
6266
build:
6367
context: ./
6468
dockerfile: ./Dockerfile
6569
depends_on:
6670
- selenium-hub
71+
- the-internet
6772
environment:
73+
- TEST_SITE=the-internet:5000
6874
- RUN_IN_DOCKER_COMPOSE=true
6975
- SELENIUM_GRID_HOST=selenium-hub
7076
- BINDING_VERSION=${BINDING_VERSION}

0 commit comments

Comments
 (0)