Created
November 24, 2021 21:19
-
-
Save asolntsev/ac6973f1db7bf6e3aa7d6e6329196ce4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package integration; | |
import com.codeborne.selenide.Configuration; | |
import com.codeborne.selenide.SelenideConfig; | |
import com.codeborne.selenide.SelenideDriver; | |
import org.junit.jupiter.api.Test; | |
import org.openqa.selenium.chrome.ChromeOptions; | |
import org.openqa.selenium.logging.LogType; | |
import org.openqa.selenium.logging.LoggingPreferences; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.logging.Level; | |
import static com.codeborne.selenide.Selectors.byText; | |
import static com.codeborne.selenide.Selenide.$; | |
import static com.codeborne.selenide.Selenide.closeWebDriver; | |
import static com.codeborne.selenide.Selenide.open; | |
import static com.codeborne.selenide.Selenide.sleep; | |
/** | |
* Works in Selenide 6.1.1 | |
*/ | |
public class CameraTest { | |
@Test | |
void pageWithCameraPermission_static() { | |
Configuration.browserCapabilities = getChromeOptions(); | |
open("https://kontroll.digilugu.ee/scan"); | |
sleep(5000); | |
$(byText("Alusta tõendi kontrollimist")).click(); | |
sleep(1000); | |
sleep(1000); | |
closeWebDriver(); | |
} | |
@Test | |
void pageWithCameraPermission_nonstatic() { | |
SelenideConfig config = new SelenideConfig().browserCapabilities(getChromeOptions()); | |
SelenideDriver driver = new SelenideDriver(config); | |
driver.open("https://kontroll.digilugu.ee/scan"); | |
sleep(5000); | |
driver.$(byText("Alusta tõendi kontrollimist")).click(); | |
sleep(1000); | |
sleep(1000); | |
driver.close(); | |
} | |
public static ChromeOptions getChromeOptions() { | |
LoggingPreferences logPrefs = new LoggingPreferences(); | |
logPrefs.enable(LogType.BROWSER, Level.WARNING); | |
ChromeOptions options = new ChromeOptions(); | |
options.addArguments("use-fake-device-for-media-stream"); | |
options.addArguments("use-fake-ui-for-media-stream"); | |
options.addArguments("--dns-prefetch-disable", "--no-sandbox", "--ignore-gpu-blacklist"); | |
Map<String, Object> prefs = new HashMap<>(); | |
prefs.put("profile.default_content_setting_values.media_stream_mic", 1); | |
prefs.put("profile.default_content_setting_values.media_stream_camera", 1); | |
prefs.put("profile.default_content_setting_values.geolocation", 1); | |
prefs.put("profile.default_content_setting_values.notifications", 1); | |
options.setExperimentalOption("prefs", prefs); | |
options.setCapability("enableVNC", true); | |
options.setCapability("screenResolution", "1920x1080x24"); | |
options.setCapability("goog:loggingPrefs", logPrefs); | |
options.setCapability("enableVideo", true); | |
return options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment