Can we change binary path location in QAF framework - selenium

I have a requirement to run application in chrome beta version using Qmetry Automation framework.
I tried to change binary path using capabilities and other different ways but none of them worked, Could please help in providing solution

Looks like issue is in capability value. Try adding goog: prefix to key chromeOptions, for example:
chrome.additional.capabilities={"goog:chromeOptions":{"binary":"Path to the Chrome executable"}}
Here is easiest way to generate or validate Capabilities:
public static void main(String[] args) {
ChromeOptions options = new ChromeOptions();
options.setBinary("Path to the Chrome executable");
System.out.println(JSONUtil.toString(options.toJson()));
}
Refer answer of similar question for another way to set capability through code using driver listener.

Related

The method attachToEdgeChrome() is undefined for the type InternetExplorerOptions using selenium-server-4.0.0-alpha-2

I want test the IE mode for Edge browser with Selenium. I found the solution on the MS site here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode?tabs=java
I am using the following code as given in the above link:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
I can get the error that the methods "attachToEdgeChrome()" and "withEdgeExecutablePath()" are not defined in the InternetExplorerOptions. Is there anything I am missing here?
Note: My selenium jar is selenium-server-4.0.0-alpha-2.jar
As per the ChangeLogs 0f Selenium v4.0.0.0-alpha-2:
Add Chromium-based Edge support. This involves adding a new Chromium driver to the tree too.
So ideally, the code block from the documentation Use Internet Explorer Driver to automate IE mode in Microsoft Edge should have worked seamlessly.
However, as per best practices instead of using the alpha and beta releases, you should always prefer the GA releases to execute your tests and you can pickup anyone from the following options:
Selenium v4.1.3
Selenium v4.1.2
Selenium v4.1.1
Selenium v4.1.0
Selenium v4.0.0

Selenium - Automated Testing and Edge

Can someone point me to a website or information that discusses how to setup Selenium and write automated scripts? I need to write scripts to test a web based application. I know how to use Java and would like to do that approach.
Thanks
From the description, it looks like you want to automate the MS Edge (Chromium) browser using Selenium web driver.
I suggest you refer to the steps below.
Download the Java binding of Selenium 4.0.0-beta-1 from here.
Download the matching version of Microsoft Edge Driver from this page.
Create a new JAVA project and try to add a reference to the Java binding files by Right-click the project folder-> Build path-> Configure Build path-> Libraries tab-> Add External JARs.
Add the code below to your JAVA project.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class test {
public static void main(String[] args)
{
System.setProperty("webdriver.edge.driver", "Edge_web_driver_path_here....\\msedgedriver.exe"); //Modify path here...
EdgeOptions edgeOptions = new EdgeOptions();
//edgeOptions.addArguments("-inprivate");
WebDriver driver = new EdgeDriver(edgeOptions);
driver.get("https://Website_URL_here..."); //Modify URL here...
//--------------------------------------
//Your_Automation_code_here....
//--------------------------------------
driver.quit();
}
}
Run the code.
Output:
Further, you can try to modify the code example as per your requirements.

How to install extension permanently in geckodriver

I need to test Firefox using an extension. I want to automate the test and visit several websites.
I installed Selenium and it opens in geckodriver. However, the extension is not there. I can install it manually from about:debugging but the problem is that I want the Selenium test to launch the gecko driver while the extension is already there. How to do this? How to install the extension permanently in the geckodriver so it is there when I launch the geckodriver from selenium?
EDIT:
I also tried to install the extension (add it to the browser) from the Firefox extensions websites. It gets added but once I close the gecko window, the extension disappear in the next run. How to install it permanently?
Note: OP didn't specify a language, so this answer is for Python. The other Selenium WebDriver language bindings have similar mechanisms for creating profiles and adding extensions.
You can install the Extension each time you instantiate the driver.
First, download the extension (XPI file) you want from: https://addons.mozilla.org.
Then, in your code... create a FirefoxProfile() and use the add_extension() method to add the extension. Then you can instantiate a driver using that profile.
For example, this will launch Firefox with a newly created profile containing the "HTTPS Everywhere" extension:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.add_extension(extension='https_everywhere-2019.1.31-an+fx.xpi')
driver = webdriver.Firefox(firefox_profile=profile)
You need to launch geckdriver with an exisitng profile by specifying the profile path of firefox
For python you can do it by this:
profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default') // change this path
browser = webdriver.Firefox(firefox_profile=profile)
For C# you can do this:
string path = #"C:\Users\username\AppData\Local\Mozilla\Firefox\Profiles\myi5go1k.default";
FirefoxProfile ffprofile = new FirefoxProfile(path);
Driver = new FirefoxDriver(ffprofile);
I found that this was warking for me:
from selenium import webdriver
driver_path = r"G:\Libs\geckoDriver\firefox\geckodriver.exe"
driver = webdriver.Firefox(executable_path=driver_path)
path = r"G:\Libs\ext\uBlock0_1.38.7b5.firefox.signed.xpi"
driver.install_addon(path, temporary=True)
driver.profile = webdriver.FirefoxProfile()
driver.profile.add_extension(path)
driver.profile.set_preference("security.fileuri.strict_origin_policy", False)
driver.profile.update_preferences()`enter code here`
Reference:
[Python] https://cyruslab.net/2020/08/26/python-adding-extension-to-geckodriver-with-selenium/
You can install an extension/addon permanently within a specific Firefox Profile and use it. To achieve that you need follow the below mentioned steps:
You need to create a new Firefox Profile manually (e.g. FirefoxExtensionProfile) following the instructions at Creating a new Firefox profile on Windows.
Open a Firefox Browsing session manually and invoke the url https://addons.mozilla.org/en-US/firefox/
In the Search Box search for an extension e.g. HTTPS Everywhere.
Click on the search result and install / enable (incase previously installed and currently disabled) the extension.
Now you can use the following Java solution to open the Firefox Profile FirefoxExtensionProfile containing the extension HTTPS Everywhere
Code Block:
package A_MozillaFirefox;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
public class A_FirefoxProfile_dc_opt {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("FirefoxExtensionProfile");
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(testprofile);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com");
}
}
Browser Snapshot:
Reference
You can find a couple of relevant discussions in:
[Python] How to load extension within chrome driver in selenium with python
[Python] How to install Chrome Extension using Selenium & Python

Unable to launch URL in edge browser - Selenium Java

I am trying to automate in Microsoft edge browser. I referred to the below links to do it and I am able to launch the browser, but it's failing to launch the URL. Can someone please help me.
Selenium Java version : 2.53.1
Tried with both of the edge drivers(insider version and webdriver), one returned null exception and not launching any browser and the other is returning unknown error after launching the browser.
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Code referred from:
stackoverflow.com/questions/31991309/selenium-on-windows-10-edge-browser
You would need to download the correct version of Edge Driver based on the OS build number. I faced this issue when I used Edge driver version which was different from my build number.
Follow the below steps (I have tried this with Selenium 3.0 Beta1 and its working fine)
Use the steps given below -
Go to Start > Settings > System > About and note down the OS Build number
Download the proper version of the driver from this link - https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
If the file that's downloaded is .msi, then install it to get the .exe driver. For one of the release, direct .exe can be downloaded.
Once the MicrosoftWebDriver.exe is downloaded, we can use it in our test script using either System.setProperty("webdriver.edge.driver", "driver location") or using environment variable
Sample Script :
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe"); //put actual location
WebDriver driver = new EdgeDriver();
driver.get("your link");
Refer this article for detailed information: http://automationtestinghub.com/selenium-3-launch-microsoft-edge-with-microsoftwebdriver/
Note : Edge browser version should be 18 or 19
This solution worked for me was by enabling Developer Mode in Windows OS:
Go to Settings -> Windows Update settings ->For Developers -> Enable Developer Mode
Run Test Script :
public class IETest {
public static void main(String[] args)
{`enter code here`
WebDriver obj=new EdgeDriver();;
obj.navigate().to("http://www.google.com");
}
}

Selenium. IEDriverServer.exe does not exist?

I get an error:
The file Capabilities [BrowserName=, IsJavaScriptEnabled=False, Platform=Any, Version=]\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list`
What must I do to solve this error because really I can't find information ....
Unless you're building the Selenium project from sources, or are using the .NET bindings and have set a specific option in the InternetExplorerOptions class, you shouldn't be seeing this message. The current source code is volatile in this particular area, as the project is currently implementing the usage of a standalone executable server for the IE driver, similar to what happens currently for the Chrome driver. If you are building from source, or are interested in using this new functionality, you should download the standalone IE driver server executable from the URL specified in the exception's message.
Download the IEDriver.exe for the given URL
http://code.google.com/p/selenium/downloads/list
Assuming the exe file is saved in E:\IEdriver.exe.
In Selenium you have to set the property of IEDriver, since Selenium has only firefox driver with it.
Set the system property and then invoke the IEDriver.
WebDriver driver;
System.setProperty("webdriver.ie.driver", "E:\\IEdriver.exe");
//Selenium will not support single slash, so we are providing double slash in path.
driver = new InternetExplorerDriver();
// By this it will call the IEDriver and execute
Thanks
An example to share:
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "D:\\selenium\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("abc");
driver.close();
}
}