We are unable to detect your camera while passing fake media to experitest chrome browser - selenium

I did not get a specific chrome option to work fine when my test is running on the server where we don't have a webcam when started chrome per the java selenium web driver script.
The goal is to mock a camera on the server and pass a fake media stream to the server machine where we don't have a webcam. The script is working fine on the local machine (because the local machine has a webcam) but it's not working on the experitest cloud browser where we don't have a webcam.
How to mock a camera on devices without a camera so that I can run my script through CI pipeline on a server or cloud browser?
The below code is working locally but not on the cloud browsers where we don't have support for the webcam and currently facing the we are unable to detect your camera error when running on a cloud browser
public class Sample {
private static final String ACCESS_KEY = "XXXX";
private RemoteWebDriver driver;
private URL url;
private DesiredCapabilities dc = new DesiredCapabilities();
#Before
public void setUp() throws Exception {
String videoSource = getClass().getClassLoader().getResource("sample1.y4m").toURI().toString();
System.out.println(videoSource);
ChromeOptions config = new ChromeOptions();
config.addArguments( //
"--use-fake-ui-for-media-stream", //
"--use-fake-device-for-media-stream", //
"--use-file-for-fake-video-capture=" + videoSource);
config.setHeadless(true);
config.setAcceptInsecureCerts(true);
dc.setCapability("testName", "Quick Start Chrome Browser Demo");
dc.setCapability("accessKey", ACCESS_KEY);
dc.setCapability(ChromeOptions.CAPABILITY, config);
dc.setCapability(CapabilityType.BROWSER_NAME, "chrome");
driver = new RemoteWebDriver(new URL("https://XXXXX/wd/hub"), dc);
}
#Test
public void virtualTryOn() {
driver.get("https://mytrialpage.com");
WebElement cookies = driver.findElement(By.id("onetrust-accept-btn-handler"));
cookies.click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[#id='virtualTryOn']")));
WebElement vto = driver.findElement(By.xpath("//button[#id='ctaVirtual']"));
vto.click();
driver.switchTo().frame("scan-iframe");
}
#After
public void tearDown() {
System.out.println("Report URL: "+ driver.getCapabilities().getCapability("reportUrl"));
driver.quit();
}
}
**
cloud browser output:
**

Related

Selenium, WebDriver Manager, and Electron Desktop Apps

I'm building out some ui automation tests for an electron app. I have an existing test framework built in C# using Selenium and Appium for web and mobile devices.
I figured out how to start the chrome driver and target the electron app, but to do so, I had to not use the extremely handy WebDriverManager package.
This is my set up
[SetUp]
public void TestSetUp()
{
ChromeOptions chromeOptions = new()
{
BinaryLocation = #"ElectronApp.exe",
};
_driver = new ChromeDriver(#"local driver path", chromeOptions);
}
This works to open up the electron app using Chrome driver. I did have to match the version of Chrome the electron app used and made sure to download that version of the webdriver.
What I want to know is if there's a good way to use WebDriver Manager to set up my driver, but open the electron app.
This was what I was trying:
[SetUp]
public void TestSetUp()
{
ChromeOptions chromeOptions = new()
{
BinaryLocation = #"ElectronApp.exe",
};
ChromeConfig chromeConfig = new();
new WebDriverManager.DriverManager().SetUpDriver(chromeConfig, "98.0");
_driver = new ChromeDriver(chromeOptions);
The 98 is the version of Chrome that the electron app is apparently using -- that's the same version I had to match the driver for.
This is the stack error:
Message:
System.Net.WebException : The remote server returned an error: (404) Not Found.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
HttpWebRequest.GetResponse()
WebClient.GetWebResponse(WebRequest request)
WebClient.DownloadBits(WebRequest request, Stream writeStream)
WebClient.DownloadFile(Uri address, String fileName)
BinaryService.DownloadZip(String url, String destination)
BinaryService.SetupBinary(String url, String zipPath, String binaryPath)
DriverManager.SetUpDriverImpl(String url, String binaryPath)
DriverManager.SetUpDriver(IDriverConfig config, String version, Architecture architecture)
DesktopTests.TestSetUp() line 41
--TearDown
DesktopTests.Teardown() line 54
I was so focused on the WebDriver Manager, I missed that the chrome version I was specifying wasn't valid. Instead, I used the full version, and it worked great.
[SetUp]
public void TestSetUp()
{
ChromeOptions chromeOptions = new()
{
BinaryLocation = #"ElectronApp.exe",
};
ChromeConfig chromeConfig = new();
new WebDriverManager.DriverManager().SetUpDriver(chromeConfig, "98.0.4758.102");
_driver = new ChromeDriver(chromeOptions);
}

How to test Electron app using selenium and java

Hi Im having an issue with testing an electron app. Up until last week our product was ran on chrome. But now the product has been changed to an electron desktop app and when launched the window isnt picked up.
The flow is basically I open the product on chrome and it appears as a pop up. Previously this was just a chrome pop up but now its an electron app. And now i cnat seem to switch to this window. Im wondering is it possible to switch between the two or do i need a different driver and just test he electron app by itself?
My driver factory is shown here
public class DriverFactory {
private static WebDriver driver;
public static WebDriver startDriver() {
String projectLocation = System.getProperty("user.dir");
// add in elements for logging into the mobile application also - Android and
// iOS.
if (OSValidator.isMac()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_mac");
} else if (OSValidator.isWindows()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver.exe");
} else {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_linux");
}
if (System.getProperty("app.env") != null) { // If coming from Jenkins/Maven goal..
// This is for logging results. Added when investigating crashes on chrome driver. Can be disabled when not needed. 26/03/2020
System.setProperty("webdriver.chrome.verboseLogging", "true");
}
unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--window-size=1920x1080");
options.addArguments("--disable-cache");
//options.addArguments("--headless");
options.addArguments("--disable-application-cache");
options.addArguments("--disk-cache-size=0");
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--dns-prefetch-disable");
//options.addArguments("--no-sandbox"); // Bypass OS security model
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
driver = new ChromeDriver(options);
//--------------------
return driver;
}
}
It is described here.
https://applitools.com/blog/automating-electron-applications-using-selenium/
You just need to set appropriate options and use same code for the chrome and electron.
#Before
public void setup() {
ChromeOptions opt = new ChromeOptions();
opt.setBinary("/Users/yanir/Downloads/Electron API Demos.app/Contents/MacOS/Electron API Demos");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", opt);
capabilities.setBrowserName("chrome");
driver = new ChromeDriver(capabilities);
if (driver.findElements(By.id("button-about")).size() > 0)
driver.findElement(By.id("button-about")).click();
}

The url is not getting loaded completely, getting an error as "[SEVERE]: Timed out receiving message from renderer

The url is not getting loaded completely, getting an error as "[SEVERE]: Timed out receiving message from renderer: -0.010" with below configurations:
Please pardon me since new to this.
Browser: Chrome 64
Selenium: 3.10.0
Build tool: maven (pom.xml)
Testng: 6.8
Scenario:
Use OWASP ZAP APIs with selenium functional test cases. below is the script:
public void login() {
// driver.get(BASE_URL);
driver.navigate().to(BASE_URL);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[#class='btn btn-link']")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
#BeforeTest
public void setup() {
zapScanner = new ZAProxyScanner(ZAP_PROXYHOST,ZAP_PROXYPORT,ZAP_APIKEY);
zapScanner.clear(); //Start a new session
zapSpider = (Spider)zapScanner;
log.info("Created client to ZAP API");
driver = DriverFactory.createProxyDriver("chrome",createZapProxyConfigurationForWebDriver(), CHROME_DRIVER_PATH);
// driver = DriverFactory.createProxyDriver("firefox",createZapProxyConfigurationForWebDriver(), FIREFOX_DRIVER_PATH);
myApp = new MyAppNavigation(driver);
// myApp.registerUser(); //Doesn't matter if user already exists, bodgeit just throws an error
System.out.println("before test is done");
}
#Test
public void testSecurityVulnerabilitiesAfterLogin() {
System.out.println("started test");
myApp.login();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// myApp.navigateAfterLogin();
log.info("Spidering...");
spiderWithZap();
log.info("Spider done.");
}
Chrome browser is launched with the given base_url however it the url doesn't load completely and gives an error as shown in the attached screen shot.

selenium grid connction with autoit not working?

selenium grid connection with auto it not working ?
#daluudaluu/PartialSeleniumGridIntegrationWithAutoItExample.java
Last active a year ago
Embed
Download ZIP
Code Revisions 2 Forks 1
Partial Selenium Grid integration support with tools like AutoIt, Sikuli, etc.
Raw
PartialSeleniumGridIntegrationWithAutoItExample.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.URL;
public class DemoTest {
public WebDriver driver;
public DesiredCapabilities capabilities;
#Before
public void setUp() throws Exception {
capabilities = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub" ), capabilities);
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#Test
public void test() throws Exception {
// Use RemoteWebDriver, grab actual node host info
driver.get("http://www.google.com");
String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
//grid info extractor from: https://gist.github.com/krmahadevan/1766772
String nodeHost = GridInfoExtracter.getHostNameAndPort("localhost", 4444, sessionId)[0];
System.out.println("Extracted hostname: "+nodeHost);
// Now use node host info to handle running AutoIt on that specific node, assuming all needed files deployed to all nodes
// Case 1 - PSExec.exe from Windows host (that is executing this Selenium code) to Selenium node that is Windows host
//String psexecCmd = "C:\\LocalMachinePathTo\\psexec.exe \\\\%s -u %s -p %s -i C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
//Process p = Runtime.getRuntime().exec(String.format(psexecCmd,nodeHost,"jdoe","hisPassword"));
//p.waitFor();
// Case 2 - winexe from *nix host (that is executing this Selenium code) to Selenium node that is Windows host
// Example reference: http://secpod.org/blog/?p=661
//String winexeCmd = "/LocalMachinePathTo/winexe -U domainName/jdoe%hisPassword //"+nodeHost+" C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
//Process p = Runtime.getRuntime().exec(winexeCmd);
//p.waitFor();
// Case 3 - have SSH installed on Windows-based Selenium nodes, now just connect to node host via SSH to run a command, i.e. execute AutoIt script binary
// no sample code given for Java, but maybe this gives you ideas on Java SSH connection:
// http://stackoverflow.com/questions/995944/ssh-library-for-java
// Case 4 - if you have implemented a custom web service (XML-RPC/SOAP/REST) for AutoIt that listens for requests/commands
// just connect to it via (Java) HTTP library to "http://"+nodeHost+"/someWebServicePath/someCommand" (via GET or POST)
// details not covered, this is just an example. Most people won't be taking this route due to customization & complexity in
// building the web service first
// Case 5 - using AutoItDriverServer that is also running on Selenium nodes
//DesiredCapabilities autoitCapabilities = new DesiredCapabilities();
//autoitCapabilities.setCapability("browserName", "AutoIt");
//WebDriver autoitDriver = new RemoteWebDriver(new URL("http://"+nodeHost+":4723/wd/hub"), autoitCapabilities);
//autoitDriver.findElement(By.id("133")).click();
//and whatever other AutoItX commands to call that you normally have in the AutoIt script that you compile into binary
//for more ideas on AutoIt commands issued as WebDriver commands with respect to Selenium integration, see:
//https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
//or if you are old school, and want to do that same approach even with AutoItDriverServer,
// assuming you have first set AutoItScriptExecuteScriptAsCompiledBinary to True in autoit_options.cfg file before starting AutoItDriverServer:
//((JavascriptExecutor) autoitDriver).executeScript("C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe");
// Case for Sikuli integration, using https://github.com/enix12enix/sikuli-remote-control
//RemoteScreen rs = new RemoteScreen(nodeHost);
//rs.setMinSimilarity(0.9);
//rs.click("D://test.png");
}
}

How to implement headless browser for secure browser (HTTPS) or validate certificate by utilizing PhantomJs in Selenium?

I need to implement Headless Browser for HTTPS (validate certificate). For this I need to write extra line of code.
I have written for browser HTTP and it is working fine.
public class Headless {
public static void main(String[] args)
{
File src=new File("C:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path",src.getAbsolutePath());
WebDriver driver=new PhantomJSDriver();
driver.get("https://www.google.co.in/");
System.out.println(driver.getTitle());
}
}
I google it and get some info:-
phantomjs --ignore-ssl-errors=yes;
DesiredCapabilities dcap = new DesiredCapabilities();
String[] phantomArgs = new String[] {
"--ssl-protocol=any",
"--ignore-ssl-errors=true"
};
dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
PhantomJSDriver driver = new PhantomJSDriver(dcap);
You can read more about the command-line options on this link: Command Line Interface | PhantomJS