How to change already set chrome options while running tests? - selenium

While sharing screen from webrtc application, user gets 3 options.
1. Share entire screen
2. Share specific tab
3. Share specific application
I need to automate these TC's. Have found a way to do it individually on different browser driver by setting chrome option like :
options = webdriver.ChromeOptions()
options.add_argument("--auto-select-desktop-capture-source=Entire screen") -- for sharing entire screen.
But is there any way to perform all 3 cases using same driver by editing chrome option run time?

Related

JMeter/Selenium ChromeDriver thread shows it is interacting with element but nothing is happening on screen

I am having an issue with using JMeter/Selenium Chrome WebDriver interacting with the element and making changes on the screen. When I look at the screen in non-headless mode nothing is happening on the screen on some of the threads. I am running 10 threads locally, waiting for a Username and Password input to display on the screen, send credentials with sendKeys and then clicking login.
The problem is, some of the threads and chrome instances are working but some others are not. I am not sure if it is a Chrome 99 issue as it seems to be happening to me recently even when I have the matching chromedriver.exe for 99. What I don't understand is why 7 or 8 will work while 2 or 3 say they are working but I cannot see it happening within the browser.
Here is a part of the Thread Group that I am running:
//Wait until the username field is visible.
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='Input_Username']")));
WDS.log.info("element clickable");
//Enter user name
var txtUserName = WDS.browser.findElement(By.xpath("//*[#id='Input_Username']")); //saves username field into txtUserName
txtUserName.click();
txtUserName.clear();
txtUserName.sendKeys("username");
WDS.log.info("Enter UserName");
//Enter password
var txtPassword = WDS.browser.findElement(By.xpath("//*[#id='Input_Password']")); //saves password field into txtPassword
txtPassword.click();
txtPassword.clear();
txtPassword.sendKeys("password");
WDS.log.info("Enter password");
//Click Login in button
var btnLogin = WDS.browser.findElement(By.cssSelector('.btn')); //saves login field into btnLogin
btnLogin.click();
WDS.log.info("clicked login");
I can see every thread hitting each one of those log.info sections but I don't see the browser making any changes or key clicks. This leads me to believe it should be working, but the browser isn't being responsive for some reason? I am just confused on if I am missing something as to why some will work but some wont. It is moving past this piece of code but failing to make any interactions so it will fail on a wait later down the line when waiting for the page after login to be displayed.
I have even tried to implement a fluent wait with polling but it will say it found it, interact with it but nothing will change on the screen. It says it clicks the login button... which on the screen if nothing is entered into those fields I would at least be seeing validation errors.
I don't think using WebDriver Samplers for creating the load is a valid use case, as per documentation:
Note: It is NOT the intention of this project to replace the HTTP Samplers included in JMeter. Rather it is meant to compliment them by measuring the end user load time.
so you should be creating the main load using HTTP Request samplers and use a separate Thread Group with 1 thread to test UI performance and rendering time while the system is under the load.
If you really want to use real browsers for conducting the load for some reason be aware that browsers are very resource intensive. Chrome doesn't state how much RAM does it need on its system requirements page but Firefox 98 needs 1 CPU core and 2 GB of RAM per instance and my expectation is that Chrome needs the same amount (if not more)
So your system should have at least 11 CPU cores and 21 GB of RAM in order to operate 10 browsers and JMeter at the same time, if your machine hardware resources are less - consider either upgrading or obtaining another machine and switching to distributed mode of JMeter tests execution

Chrome Driver default resolution

My front-end developers, changed the layout of the application which I'm testing, therefore some buttons are in slightly different places. I have about 50 automated tests that I will have to improve if the idea I came up with proves to be ineffective. Namely, is it possible to change the size of the pages opened by default via Headless Chrome Driver? Most of my tests are as follows: open the website > log in > click the button on the top bar of the application. The problem is that the buttons have been hidden under the hamburger button, and one of the ways to "see" them is to reduce the resolution of Google Chrome to 80%, so is it possible to program Chrome Driver and/or Geckodriver to open websites and web apps in 80% resolution by default?
There is a way to achieve the browser resolution changes before tests are actually started. Below codes are for java and you can add them to your driver options. You can find your desired resolutions and then you can change the values.
ChromeOption for 1920 x 1080 :
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1920,1080");
Firefox options for 1920 x 1080 :
FirefoxDriver firefoxOptions = new FirefoxDriver();
firefoxOptions.addArguments("-width=1920");
firefoxOptions.addArguments("-height=1080");
You can also change resolution after driver initialization with dimension, here is an example for 1920 x 1080 :
Dimension dimensions = new Dimension(1920,1080);
driver.manage().window().setSize(dimensions);
For Magnification feature of browser you can use below codes :
Magnification + :
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.ADD));
Magnification - :
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));

Firefox - hide browser frame with Selenium

I'm trying to figure out how to hide the border (including the address bar, tabs, title bar... everything that isn't the browser viewport) of my Firefox instance instantiated by Selenium.
If there's some way to have it use a userChrome.css, that would be straightforward enough. I've tried loading a profile folder that included a userChrome.css using this answer as a guide, but it seemed to ignore the styles. I've also looked through Firefox's about:config to see if there's some preference that would hide the frame of the window, but I haven't found anything yet.
Any solution that allows me to hide all or some of these elements when creating the instance with Selenium would be helpful. I know it's silly, but that's how it goes sometimes, you know?
-edit-
I don't think the title bar needs to be hidden. But everything else should be hidden.
-another edit to clarify a few things-
I mentioned kiosk mode in the comments as an example of the sort of thing I'm going for. Kiosk mode isn't exactly what I'm looking for, though. The windows aren't meant to be fullscreen, but they should still lack the elements of a common browser window. Think of it as like an Electron app. Out of the box, Electron lacks an address bar, tabs, etc. That's basically what we have for our app, but it's with regular-old Firefox. Again, whether these elements are displayed or not doesn't typically impact the test, but we want them hidden anyway.
Finally, I a friend of mine tried achieving this goal using a userChrome.css wrapped in a Firefox profile and was able to get Selenium to use the userChrome. So perhaps I need to figure out what I'm doing wrong. The biggest difference between how he did it and how I'm doing it is I must use a remote web driver for testing. But even still, it should be able to load the userChrome.css file. I'll try to update this question with more details as I fiddle with it some more.
-edit-
I think the reason userChrome isn't working when specifying a profile is because of the version(s) of Selenium/Geckodriver/Firefox being used.
The geckodriver version I started with was 0.15. 0.17 behaved exactly the same. 0.18 didn't respect the profile I passed along to it at all and instead had Firefox open the profile selection window (not very useful, but I was able to at least select the correct profile and see the userChrome.css get applied). 0.24 is no different.
Firefox is 52.9.0. Not much I can do about that.
We're using selenium (standalone) server 3.8.1. Switching out for 3.141.59 Didn't change anything.
Unless there's a version combination that will work with Firefox 52, I think the only thing I can do is wait until there's an update.
At last I have figured it out. In order to get Selenium to use my custom profile, I needed to do the following:
FirefoxProfile profile = new FirefoxProfile(new File(path_to_profile));
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
RemoteWebDriver driver = new RemoteWebDriver(options.toCapabilities());
driver.get(url_of_webpage);
Thanks to avinesh09 on Github for the info I needed to solve the problem. It's so simple, but this has to be the only way that I neglected to try to load the profile.
If fullscreen (kiosk) mode is what you ask for (as then all you see is the viewport) it is as simple as:
driver.manage().window().fullscreen();
It is the same user experience as pressing "F11" in your browser.

Selenium WebDriver: is it possible to test WebExtension that inject code to the current page?

I found articles about opening browser extension as a page - but my extension inject JS to the current page - and extension can not inject code to chrome* pages. My only choice is SikuliX? Also with SikuliX I can test the badge of my button. I think that with SikuliX I simulate real user behaviour - such tests about UI interactions looks like more robust for me. Also nice to test CSS correctness.
I tried to setup a hotkey for my extension:
But
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'I') (Python) or driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL + "I") (Java)
do nothing, but I can press Ctrl+I and I see popup-UI opened.
UPDATE: I tried to use pyautogui for mouse clicking - but even with opened extension popup UI driver.window_handles does not include it :(
You can configure webdriver to load your extension in to the browser while launching as well. Once your extension in loaded , it can inject required code that i am assuming makes some changes to html such as adding / removing some html elements or applying some styles which can be then tested using Selenium. You can also execute javascript using selenium.
Sikuli framework is based on image recognition and then simulating user interactions on it using mouse and keyboard . Your test cases might break under these scenarios :
Change in resolution which may even result in layout changes
Change in theme of the application resulting in color changes of ui-elements
It will require focus ,etc.
Currently, I test my extension by comparing expected and actual screenshots, using Selenium web driver, pyautogui (for interactions with extension) and opencv2 (for computer vision), see more at https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/

Can a website detect when you are using selenium with geckodriver?

Is it possible to detect instances of firefox browsers that are being controlled by Selenium and geckodriver?
Note there is a corresponding answer for chromedriver, but I'd like to know whether this is possible for firefox/geckodriver.
Yes you can detect geckodriver controlled selenium with a simple check in JavaScript
var runningSelenium = !("showModalDialog" in window);
As others have pointed out, there are a variety of different ways that a site can fingerprint and detect that you are running a browser that has been automated by selenium. Luckily though, some of the detection mechanisms are remarkably simple and just look for a bunch of environmental defaults, such as the screen size etc.
For example, when using Selenium for testing the app OAUTH sign-up sequences for Dropbox etc, the CAPTCHA stage can be avoided by just setting the screen to a non-default value (and offsetting the browser window to simulate a taskbar):
##headless = Headless.new( dimensions: '1600x1200x24' )
##headless.start
browser = Watir::Browser.new :firefox
width = browser.execute_script( 'return screen.width;' )
height = browser.execute_script( 'return screen.height;' ) - 95
browser.driver.manage.window.resize_to( width, height )
browser.driver.manage.window.move_to( 0,0 )