Skip to content

Commit 8eb4b03

Browse files
committed
Include cross-browser tests based on JUnit's @ParameterizedClass
1 parent 08d689c commit 8eb4b03

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia.webdriver.jupiter.ch08.cross_browser;
18+
19+
import java.util.stream.Stream;
20+
21+
import org.junit.jupiter.api.extension.ExtensionContext;
22+
import org.junit.jupiter.params.provider.Arguments;
23+
import org.junit.jupiter.params.provider.ArgumentsProvider;
24+
import org.openqa.selenium.chrome.ChromeDriver;
25+
import org.openqa.selenium.firefox.FirefoxDriver;
26+
27+
public class CrossBrowserDriverProvider implements ArgumentsProvider {
28+
29+
@Override
30+
public Stream<? extends Arguments> provideArguments(
31+
ExtensionContext context) {
32+
ChromeDriver chrome = new ChromeDriver();
33+
FirefoxDriver firefox = new FirefoxDriver();
34+
35+
return Stream.of(Arguments.of(chrome), Arguments.of(firefox));
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia.webdriver.jupiter.ch08.cross_browser;
18+
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.params.Parameter;
21+
import org.junit.jupiter.params.ParameterizedClass;
22+
import org.junit.jupiter.params.provider.ArgumentsSource;
23+
import org.openqa.selenium.WebDriver;
24+
25+
@ParameterizedClass
26+
@ArgumentsSource(CrossBrowserDriverProvider.class)
27+
class CrossBrowserParent {
28+
29+
@Parameter
30+
WebDriver driver;
31+
32+
@AfterEach
33+
void teardown() {
34+
driver.quit();
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia.webdriver.jupiter.ch08.cross_browser;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
class CrossBrowserTest extends CrossBrowserParent {
24+
25+
@Test
26+
void test() {
27+
driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
28+
assertThat(driver.getTitle()).contains("Selenium WebDriver");
29+
}
30+
31+
}

0 commit comments

Comments
 (0)