ChromeAndroidUser.java 2.32 KB
Newer Older
1
/*
2
 * (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

18
package io.openvidu.test.browsers;
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ChromeAndroidUser extends BrowserUser {

	public ChromeAndroidUser(String userName, int timeOfWaitInSeconds) {
		super(userName, timeOfWaitInSeconds);

		Map<String, String> mobileEmulation = new HashMap<>();
37
		mobileEmulation.put("deviceName", "Pixel 2");
38

39 40
		ChromeOptions chromeOptions = new ChromeOptions();
		chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
41 42 43

		DesiredCapabilities capabilities = DesiredCapabilities.chrome();
		capabilities.setAcceptInsecureCerts(true);
44
		capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
45 46

		// This flag avoids to grant the user media
47
		chromeOptions.addArguments("--use-fake-ui-for-media-stream");
48
		// This flag fakes user media with synthetic video
49
		chromeOptions.addArguments("--use-fake-device-for-media-stream");
50 51 52 53 54 55 56 57 58 59 60

		String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
		if (REMOTE_URL != null) {
			log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
			try {
				this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
		} else {
			log.info("Using local web driver");
61
			this.driver = new ChromeDriver(capabilities);
62 63 64 65 66 67 68
		}

		this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
		this.configureDriver();
	}

}