Тестовый сценарий:
Код: Выделить всё
@BeforeMethod
public void setUp() throws MalformedURLException {
folder = new File("target");
for(File file : folder.listFiles()) {
file.delete();
}
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
ChromeOptions options = new ChromeOptions();
Map prefs = new HashMap();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", folder.getAbsolutePath());
options.setExperimentalOption("prefs", prefs);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("chrome");
cap.setCapability(ChromeOptions.CAPABILITY, options);
//driver = new ChromeDriver(cap);
//driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver = new RemoteWebDriver(new URL("http://docker:4444/wd/hub"), cap);
}
@AfterMethod
public void tearDown() {
driver.quit();
}
@Test
public void downloadFileTest() throws InterruptedException {
driver.get("http://the-internet.herokuapp.com/download");
driver.findElement(By.linkText("some-file.txt")).click();
Thread.sleep(2000);
File listOffFiles[] = folder.listFiles();
Assert.assertTrue(listOffFiles.length > 0);
for(File file : listOffFiles) {
Assert.assertTrue(file.length() > 0);
}
}
Код: Выделить всё
version: "3"
services:
chrome:
image: selenium/node-chrome:4.0.0-20211013
container_name: chrome
shm_size: 2gb
depends_on:
- selenium-hub
volumes:
- ./target:/home/seluser/Downloads
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_GRID_URL=http://localhost:4444
ports:
- "6900:5900"
selenium-hub:
image: selenium/hub:4.0.0-20211013
container_name: selenium-hub
ports:
- "4444:4444"
Код: Выделить всё
image: adoptopenjdk/openjdk11
stages:
- gradle-build
- docker-test
.gradle_template: &gradle_definition
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=${CI_PROJECT_DIR}/.gradle
gradle-build:
Подробнее здесь: [url]https://stackoverflow.com/questions/69974278/how-to-set-up-a-selenium-test-of-download-a-file-in-gitlab-ci[/url]
Мобильная версия