Strange issue when running tests on Chrome? - google-chrome

I am trying to run some simple tests on Chrome, and I have followed all required steps to do this. The tests start fine, the Chrome browser opens and is initialized correctly (it seems), but when my tests start to search for objects and check values on the web page.
(e.g.
[#browser.div(:id, "example").text.should == "test"]
or
[puts #browser.div(:id, "example").text]
) I get the next error and my tests fail: "Selenium::WebDriver::Error::UnkownError:".
This is it, only this message appears, with no clues or details on the error.
I simply do not know were to look for answers. I even tried to debug the tests but with no results.
I even search on known issues on chromedriver, but found nothing.
Another thing to mention is that the tests suite create by me is for cross browser testing.
These tests work fine on Firefox.
Am I doing something wrong in initializing the Chrome browser?
Here is the code from my env file:
require "rubygems"
require "rspec"
require "watir-webdriver"
require "watir-webdriver/extensions/alerts"
if ENV["HEADLESS"] then
include Selenium
capabilities = WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)
elsif ENV["FIREFOX"] then
browser = Watir::Browser.new :firefox
elsif ENV["CHROME"] then
browser = Watir::Browser.new :chrome
elsif ENV["IE"] then
browser = Watir::Browser.new :ie
else
browser = Watir::Browser.new :chrome
end
Before do
#browser = browser
end
at_exit do
browser.close
end
I have tried also with the latest release in selenium-webdriver gem, and after this with an older version 2.21.0. Results are the same.
Can you give me a clue what am I doing wrong?
Thank you.

Well, obviously I did not checked with the latest version of chromedriver :).
The version from which the issue stops reproducing is the one from 23 of May 2012.
Thank you for the hint Željko!

Related

How to get job and telescope command on chrome's V8 x64.release version? (No symbol "_v8_internal_Print_Object" in current context)

I'm trying to get chrome's V8 (d8) x64.release version to use the V8 support tools in GDB, specifically for the job and telescope commands (predominantly the former).
My x64.debug version has this implemented and works, but even after building the x64.release version in a similar manner I still cannot get these commands to work in the x64.release version. The output is always as:
gef➤ job 0xd98082f7b51
No symbol "_v8_internal_Print_Object" in current context.
I have set args.gn before, and after building via ninja -C to include v8_enable_object_print = true in my args.gn:
is_debug = false
target_cpu = "x64"
use_goma = false
v8_enable_object_print = true
v8_enable_disassembler = true
I also have my ~/.gdbinit containing:
source ~/Desktop/tools/v8/tools/gdbinit
source ~/Desktop/tools/v8/tools/gdb-v8-support.py
See: https://chromium.googlesource.com/v8/v8/+/refs/heads/main/tools/gdbinit (for the support tool I'm trying to build V8 with).
How can I get my /v8/out.gn/x64.release/d8 to run with compatibility of the job command?
Am I missing something here? If so your help would be very helpful.
EDIT Alternatively how can I disable all x64.debug V8 DCHECKS?
Thanks all, appreciate your time here.
How can I get my /v8/out.gn/x64.release/d8 to run with compatibility of the job command?
I'm not sure. Try adding symbol_level = 1 (or even symbol_level = 2) to your args.gn. That definitely helps with stack traces, and might also be the thing that lets GDB find the _v8_internal_Print_Object function by name.
Alternatively how can I disable all x64.debug V8 DCHECKS?
There is no flag to disable them, but you can edit the source to make them do nothing. See src/base/logging.h.

Permission issue for appium chrome borwser

I am implementing an appium test on remote android driver, with chrome browser for loading urls.
Some of the Urls are pdfs, and chrome asks to store those files. and appears that chrome doesnt have access to filesystem to store those files, which results in a dialog like below.
Please help me pass that dialog without any manual inputs.
Upon clicking continue, it will load actual permissions dialog from Android.
Here is my code initialize appium capabilities
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.9.1");
caps.setCapability("deviceName","Samsung Galaxy S9 Plus HD GoogleAPI Emulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "Chrome");
caps.setCapability("platformVersion", "8.1");
caps.setCapability("platformName","Android");
caps.setCapability("autoAcceptAlerts", true);
caps.setCapability("autoGrantPermissions", true);
caps.setCapability("chromedriverArgs", "--allow-file-access-from-files");
caps.setCapability("maxDuration", 10000);
and this is the snippet I use to load a Url
driver.navigate().to("http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf");
autoGrantPermission also doesnt work in this case because chrome is already installed. Appium team has already rejected this issue -
https://github.com/appium/appium/issues/10008
Please help!
Indeed I had very hard time finding out the solution, but eventually I found a workaround.
The best workaround would have been reinstalling the chrome package. I tried that, but I could not start chrome after reinstalling it, as I had no access to shell, and chromedriver complained. So I left that track.
I tried getting hold of adb command or mobile:changePermissions but for that you need to use server flag --relaxed-security while starting the server, and saucelabs doesnt provide any handy interface to start the server with this flag.
The last resort, I found a solution here - https://stackoverflow.com/a/51241899/4675277 . But just that was not sufficient, because it helped me fix chrome alert, but later on it popped up with another alert with allow and deny, for which another solution in the same question helped me. So this is the code I eventually used -
driver.navigate().to("http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf");
String webContext = ((AndroidDriver)driver).getContext();
Set<String> contexts = ((AndroidDriver)driver).getContextHandles();
for (String context: contexts){
if (context.contains("NATIVE_APP")){
((AndroidDriver)driver).context(context);
break;
}
}
driver.findElement(By.id("android:id/button1")).click();
contexts = ((AndroidDriver)driver).getContextHandles();
for (String context: contexts){
if (context.contains("NATIVE_APP")){
((AndroidDriver)driver).context(context);
break;
}
}
driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button")).click();
((AndroidDriver)driver).context(webContext);
This helps allow all permissions required.

play DRM content in chrome driver

I'm writing some selenium tests for a HTML5 player playing DRM content, the player works fine in Chrome when I test it manually, but nothing is loaded or played in the latest chrome driver if I run my test cases.
Is it because of the drm content isn't authorized to play in chrome driver or something else?
I have no issues running tests for other functions written in selenium.
Any ideas?
Chromedriver launches Chrome with --disable-component-update switch by default, which disables the NaCl (Native Client) support, which is in turn required to load DRM modules (e.g. Widevine Modular DRM).
To get around this, you need to tell the driver not to launch Chrome with this switch, by building the driver with excludeSwitches option, specifying disable-component-update parameter. For example (JS):
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");
var capabilities = new webdriver.Capabilities.chrome();
var chromeOptions = {
'args': ['--user-data-dir=C:/ChromeProfile'], // start with pre-configured Chrome profile
'excludeSwitches': ['disable-component-update'] // stop breaking Native Client support
};
capabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().
withCapabilities(capabilities).
build();
driver.get('http://...');
Or using Python bindings:
from selenium import webdriver
def buildDriver():
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')
return webdriver.Chrome(chrome_options=options)
Hope that helps..
-- ab1
Issue 886: Enabled PNaCl Components in ChromeDriver - Enhancement
If you cannot get #Chainik's answer to work, try this out. It worked for me.
As per https://bugs.chromium.org/p/chromedriver/issues/detail?id=1140 you can work around this issue by doing a few things.
manually start chrome from terminal/command prompt with these command line arguments --
google-chrome --user-data-dir=/path/to/any/custom/directory/home/user/Desktop/Chromedir --profile-directory="Profile 1" --remote-debugging-port=7878
make sure "Profile 1" is already existing in the same --user-data-dir (make usre Profile 1 has necessary chrome://components/ to run Netflix when launched manually)
you can use any free port in place of 7878
verify that http://localhost:7878 is running and returns value.
now connect to the remote-debugging-port=7878 via chromedriver with code below
Verify chrome://components/
I put mine into a .bat file, but you could do the same for a bash script or whatever:
C:/Program Files (x86)/Google/Chrome/Application/chrome.exe --user-data=c:/temp/chromeprofile --profile-directory="Profile 1" --remote-debugging-port=7878
Then set the debugger address in your code to use the browser:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
cr_options = Options()
# This line is where the "magic" happens.
cr_options.add_experimental_option('debuggerAddress','127.0.0.1:7878')
browser = webdriver.Chrome(chrome_options=cr_options)
browser.get('https://www.google.com')
browser.get('chrome://components/')
I'm post a java version of Chainik's answer as a reference for those using Java, please let me know if there's anything wrong.
ChromeOptions options = new ChromeOptions();
List<String> list = new ArrayList<String>();
list.add("disable-component-update");
options.setExperimentalOption("excludeSwitches", list);
options.addArguments("user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/Default");
java.lang.System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
Webdriver driver = new ChromeDriver(options);
Here is an article about chromedriver capabilities and options.
This is late but might help someone else. I was able to get around this and play videos by not using a headless browser.
In Python,
options = Options()
options.headless = False
webdriver.Chrome(executable_path='path/to/chromedriver', options=options)

Selenium::WebDriver Wait (Ruby, Chrome)

I have a ruby script that opens a browser. I have it set to open Firefox first and then Chrome if FF fails for some reason - like FF gets updated and Selenium hasn't caught up yet.
The wait function/definition works fine for FF but always breaks Chrome. Here is the relevant code for the Chrome browser startup:
b = Selenium::WebDriver.for :chrome
b.driver.manage.timeouts.implicit_wait = $BROWSER_IMPLICIT_WAIT
I'm fairly new to Selenium still and I user the wait.until command after declaring something like:
wait = Selenium::WebDriver::Wait.new(:timeout => $BROWSER_EXPLICIT_WAIT)
The above lines of code work fine in Firefox. However, I'd like to run my scripts with both FF and Chrome. Is there a way to do this in Chrome and FF?
Thanks
See now that you provide the error it gets easier to solve.
The reason is that - you have named the selenium driver instance as b
but defining the implicit time as
b.driver.manage.timeouts.implicit_wait = $BROWSER_IMPLICIT_WAIT
ie with b.DRIVER, hence the error message - undefined method 'driver' for
change your command to
b.manage.timeouts.implicit_wait = $BROWSER_IMPLICIT_WAIT

NPAPI plugin does not show in about:plugins in google chrome

I have gone through the questions in this forum regarding this issues, but I have not found any query related to the kind of issue that I am facing. I have written a NPAPI plugin which works fine with GtkLauncher (comes with webkit) and firefox, but with google-chrome (18.0.1025.151), the plugin is not even showing up in about:plugins. I am running on Ubuntu 10.10.
When I am loading the plugin in google-chrome, in the browser I am getting failed to load plugin error but nothing is shown on the console. I doubt whether my NP_Initialize function is getting called.
Here is the NP_Initialize code:
-------------------------------
NPError OSCALL
NP_Initialize(NPNetscapeFuncs *npnf
#if !defined(_WINDOWS) && !defined(WEBKIT_DARWIN_SDK)
, NPPluginFuncs *nppfuncs)
#else
)
#endif
{
MEDIA_DEBUG_PRINT("\nwcf Media plugin: NP_Initialize");
if(npnf == NULL)
return NPERR_INVALID_FUNCTABLE_ERROR;
if(HIBYTE(npnf->version) > NP_VERSION_MAJOR)
return NPERR_INCOMPATIBLE_VERSION_ERROR;
npnfuncs = npnf;
#if !defined(_WINDOWS) && !defined(WEBKIT_DARWIN_SDK)
NP_GetEntryPoints(nppfuncs);
#endif
return NPERR_NO_ERROR;
}
NPError OSCALL
NP_GetEntryPoints(NPPluginFuncs *nppfuncs)
{
MEDIA_DEBUG_PRINT("\nwcf Media plugin: NP_GetEntryPoints");
nppfuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
nppfuncs->newp = nevv;
nppfuncs->destroy = destroy;
nppfuncs->getvalue = getValue;
nppfuncs->event = handleEvent;
nppfuncs->setwindow = setWindow;
return NPERR_NO_ERROR;
}
I know there is a Firebreath framework for cross browser development which I have plan to use but at present I need to get my plugin running on chrome.
Can some one please help me to solve my issue?
Thanks and Regards,
Souvik
Chrome tends to be a bit pickier about how things start up. I don't see anything here that would be likely to cause your issue, but Chrome is notorious for rejecting plugins that don't behave as it expects. Most likely your issue is later on; you say you doubt that your NP_Initialize is getting called, if I were you I'd verify that. Have it write to a file in /tmp/ or something to make sure.
Also you haven't provided any of your other entrypoints such as NP_GetPluginVersion or NP_GetMimeDescription. Those are needed as well for a linux plugin and could very possibly be responsible for an issue like this. For reference, take a look at FireBreath's X11 entrypoint file.
Finally, it's possible that the way you installed the plugin it is found by mozilla and not by chrome; how did you install it?
If your plugin isn't showing in chrome://plugins, then it's failing during the initial plugin scan. Try running with the --debug-plugin-loading flag, which should give you a log statement at the point where registering your plugin is failing.