I am trying to setup an automated test environment using
- TestStack.Seleno v0.8.2
- TestStack.BDDfy v4.0.0
- Selenium .NET WebDriver 2.43.0.0
- Chrome v38
- ChromeDriver v2.9
While I am able to establish initial session hand shake between chrome driver and chrome browser, subsequent calls to actual web application via chrome driver are failing with timeout exceptions.
Here is the code to instantiate a SelenoHost object :
var options = new ChromeOptions();
Instance.Run(configure => configure
.WithWebServer(new InternetWebServer(String.Format("http://{0}/portal", IISServerHost)))
.WithRemoteWebDriver(() => BrowserFactory.Chrome(options))
.UsingLoggerFactory(new ConsoleFactory()));
If I debug the above method call, it fails inside SelenoApplication Initialize method :
public void Initialize()
{
_initialised = true;
_logger.Debug("Starting Webserver");
WebServer.Start();
_logger.Debug("Browsing to base URL");
Browser.Navigate().GoToUrl(WebServer.BaseUrl); >>> this line fails inside HttpCommandExecutor.CreateResponse() method
}
Not able to figure out what obvious am i missing out here.
BTW, web application is hosted on IIS 7.5 and is configured for windows authentication.
Launching chrome with 'no-sandbox' resolved the issue.
Here is how the final configuration looks like :
var options = new ChromeOptions();
options.AddArgument("ignore-certificate-errors");
options.AddArgument("no-sandbox");
var driverService = ChromeDriverService.CreateDefaultService();
driverService.EnableVerboseLogging = (ChromeDriverVerboseLogigng == "true");
driverService.LogPath = ChromeDriverLogPath;
_SelenoHostLazy.Value.Run(configure => configure
.WithWebServer(new InternetWebServer(String.Format("http://localhost/portal", IISServerHost)))
.WithRemoteWebDriver(() => new ChromeDriver(driverService, options))
.UsingLoggerFactory(new ConsoleFactory()));
Related
Good Morning,
I'm using Katalon studio to automate my testing, and I need to launch the chrome driver using selenium, then use it to call Web UI methods in the test cases. the driver launched and opened successfully, but the Web UI methods such as (click, send keys…) in the test cases marked as passed while actually they didn’t, therefore the next step can’t be executed.
it’s noteworthy that the same method sometimes works and sometimes doesn’t.
My Code
def public downloadDocumentSetup() {
String OldDownloadsPath=RunConfiguration. getProjectDir () + "/Downloads"
String DownloadsPath= OldDownloadsPath.replace("/", "\\")
HashMap<Object, String> chromePrefs = new HashMap<Object, String>();
chromePrefs.put("download.default_directory", DownloadsPath)
chromePrefs.put("profile.default_content_settings.popups",0)
chromePrefs.put("download.prompt_for_download", false)
chromePrefs.put("safebrowsing.enabled", "true");
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption("prefs", chromePrefs)
DesiredCapabilities cap = DesiredCapabilities.chrome()
cap.setCapability(ChromeOptions.CAPABILITY, options)
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver = new ChromeDriver(cap)
DriverFactory.changeWebDriver(driver)
RunConfiguration. setWebDriverPreferencesProperty ("prefs", chromePrefs)
}
My Test Case
WebUI.navigateToUrl(GlobalVariable.WWWSite)
WebUI.click(findTestObject(‘Pages/MyFirstObject’))
WebUI.click(findTestObject(‘Pages/MySecondObject’))
Result
The browser opened and navigated to the website successfully, and the first click step marked as passed but actually it didn’t pass, therefore the next click action is not working.
Note
My Test case works perfectly when I use ‘Open Browser’ method to launch the driver.
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);
}
I have paid/rented a proxy server in brazil
String proxyAddress = "myusername:myuserpass123#196.18.199.51:15464"
proxy.setAutodetect(false);
proxy.setHttpProxy(proxyAddress);
proxy.setSslProxy(proxyAddress);
chromeOptions.setCapability(CapabilityType.PROXY, proxy);
WebDriver webDriver = new ChromeDriver(chromeOptions);
I m running the webdriver on my local computer and I am in Indonesia. When the chrome browser opens up, I can debug and made sure that capabilities were set correctly: I can see the manual proxy setting set to the correct address string above.
However, when webdriver opens https://api.ipify.org/?format=json, it still returns my IP in Indonesia. What am I Missing here? My expectation is because I had configured webdriver to be proxied by a server in Brazil, https://api.ipify.org/?format=json should return Brazilian IP address?
Using Selenium 4 BiDirectional API (https://www.selenium.dev/documentation/webdriver/bidirectional/bidi_api/)
Register Basic Auth.
Some applications make use of browser authentication to secure pages. With Selenium, you can automate the input of basic auth credentials whenever they arise.
//C#
//Console App .NET 6
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
Proxy proxy = new Proxy();
var proxyAddress = "address:port";
proxy.HttpProxy = proxyAddress;
proxy.SslProxy = proxyAddress;
ChromeOptions options = new ChromeOptions();
options.Proxy = proxy;
IWebDriver driver = new ChromeDriver(options);
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
{
UriMatcher = (d) => d.Host.Contains("your-domain.com"), // or set it `true` to enable proxy everywhere
Credentials = new PasswordCredentials("admin", "password")
};
INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);
await networkInterceptor.StartMonitoring();
driver.Navigate().GoToUrl("https://api.ipify.org/?format=json");
await networkInterceptor.StopMonitoring();
I'm trying to test my firefox webextension but firefox refuses to install it because it doesn't have the install.rdf file. But that file is not used anymore by webextensions.
const firefox = require('selenium-webdriver/firefox');
const webdriver = require('selenium-webdriver');
require('geckodriver');
let profile = new firefox.Profile();
profile.addExtension(process.cwd() + '/build/firefox/');
profile.setPreference('extensions.firebug.showChromeErrors', true);
let options = new firefox.Options().setProfile(profile);
let _driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
Error: ENOENT: no such file or directory, open '/dev/webext/build/firefox/install.rdf'
Is there a setting that I need to enable to tell it it's a webextension?
The WebExtension API is not yet supported by Selenium v3.4.0 . The method Profile::addExtension only works for a legacy addon where install.rdf is present at the root.
To test a web extension, you can either use a profile where the extension is already installed, or you can implement the custom command available with GeckoDriver since v0.17.0:
var webdriver = require('selenium-webdriver');
var Command = require('selenium-webdriver/lib/command').Command;
function installWebExt(driver, extension) {
let cmd = new Command('moz-install-web-ext')
.setParameter('path', path.resolve(extension))
.setParameter('temporary', true);
driver.getExecutor()
.defineCommand(cmd.getName(), 'POST', '/session/:sessionId/moz/addon/install');
return driver.schedule(cmd, 'installWebExt(' + extension + ')');
}
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
installWebExt(driver, "C:\\temp\\extension.zip");
This is an issue with FirefoxDriver. This issue is already logged in both SeleniumHQ/selenium#4184 and
mozilla/geckodriver#759
GeckoDriver says that
A workaround for the time being would be to use the add-on endpoints
geckodriver 0.17.0 provides to get an extension installed from the
local disk.
https://github.com/mozilla/geckodriver/blob/release/src/marionette.rs#L66
So you have to use the geckodriver endpoints to do that. I have already mentioned on how to use the endpoints here
I am trying to run my testng test cases from command prompt. I can see browser's instance are created in task manager but it is not launching with given URL. I debugged the code and found it is failing on new ChromeDriver() below line but there is no exception.
On command line, I can see below message :
Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 7108
Only local connections are allowed.
Browser instance will create in task manager but it will not launch and will not go to next line.
This issue is coming from all browsers on same line.
same code worked well in Eclipse.
Using Selenium 2.53.0 and testng 6.9.13 versions
Try this solution:
ChromeDriverService service = null;
try
{
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chromeDriver))
.usingAnyFreePort()
.build();
service.start();
}catch(IOException io){}
if(service.isRunning())
{
DesiredCapabilities cap = DesiredCapabilities.chrome();
try{
driver = new RemoteWebDriver(service.getUrl(), cap);
}catch (SessionNotCreatedException e)
{
}
}