I was trying to download the android apk file located at Hockey App share point but could only download a part of file not the complete file. Below is the code attached.
Below is the code that I have used to alter firefox configuration to handle the download pop-up
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
// profile.setPreference("browser.download.dir", "Downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.android.package-archive");// MIME type for apk file
WebDriver driver = new FirefoxDriver(profile);
Also, I tried using Content Type header("text/html; charset=utf-8") value shown in the Network monitor of Firefox. But that didn't work as well.
Any other approach other than Selenium is also appreciated.
Why don't you use the api provided by hockey app. Its pretty easy .. you can get the build url from available versions and then download. I have written a script pretty straightforward.
https://support.hockeyapp.net/kb/api
P.S. You should use the token from a developer account . Tester account doesnt get the build_url. But that shouldnt be difficult just ask for a read only token.
Related
I am using Selenium with Robot Framework to run an Electron application. The application is built to read a configuration file from the user data directory. As far as I understand, this is the location where this file should be stored.
The electron main process reads the configuration file:
const localConfigFile = path.join(app.getPath('userData'), 'config.json');
const localConfig = fs.existsSync(localConfigFile) ? require(localConfigFile) : {};
The built production version works just fine and reads the file as expected, but when starting it from Robot using SeleniumLibrary, the file is not read. This leads me to believe it's a problem with Robot, Selenium or ChromeDriver.
Robot creates the webdriver using SeleniumLibrary:
Create Webdriver Remote desired_capabilities=${starting_parameters} command_executor=http://127.0.0.1:9515
Where starting parameters are simply:
{ "chromeOptions": {"binary": <binary_location> }}
Chromedriver is started as a separate process from /usr/bin/chromedriver where it has been installed and uses the default port 9515.
The versions that I am using are:
ChromeDriver 2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752)
"electron": "^6.0.2"
"electron-builder": "^21.2.0"
robotframework==3.2.1
robotframework-seleniumlibrary==3.3.1
Ubuntu 18.04.4 LTS
Experienced the same problem. Finally changing the Chromedriver's user-data-dir argument to Electron's userDataDir solved the problem.
options.add_argument('--user-data-dir=' + str(app_config_path()))
I found out the problem by using Spectron and logging the Electron main console. In general I would advice using Spectron instead of Robot to test Electron apps.
The issue is that the user data directory was not the same as the Electron default. When running the application through Chromedriver, the user data directory is changed to /tmp/somethingsomething so naturally the file under ~/.config/app-name was not found.
My solution was to use Electron'ss application data directory instead:
app.getPath('appData')
By default this is one directory up from the user data directory, but remains the same when running through Chromedriver.
I read through a ton of answers to this query of mine but couldn't find anything specific. Hence asking here
Here's the scenario, On a webpage, when I click a download button, it downloads a PDF file correctly, On the browser, I have set the Firefox preferences to save the file rather than open in preview.
However, when I run my selenium/Python script, the download keeps opening in the preview, there are other PDF downloads on the page and they work fine. Upon inspecting both the download buttons, the only difference I see is the one that does not download has a relative URL in its href value.
I am also using the following firefox options settings in my script, but with no help. Please guide me in the right direction. Thanks in advance!
**************************
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", 'Path to Save The file')
fp.set_preference("pdfjs.enabledCache.state", False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
fp.set_preference("pdfjs.disabled", "true")
# disable Adobe Acrobat PDF preview plugin
fp.set_preference("plugin.scan.plid.all", "false")
fp.set_preference("plugin.scan.Acrobat", "99.0")
self.driver = webdriver.Firefox(firefox_profile=fp,executable_path="path to my geckodriver")
self.driver.get("url")
I had the same problem - setting to disable pdfjs only worked when clicked manually on about:config page. Turned out that what seems to have solved the issue was (Firefox 60.6.1ESR):
profile.setPreference("pdfjs.disabled", true);
profile.setPreference("pdfjs.enabledCache.state", false); // <= THIS
I've scenario like when clicking on one button its opening a Window Based PDF File:
I'm using Gecko driver Version -21.0 Firefox Version -61.0.1 Selenium Stand alone Server -3.13
I'm unable to switching to the window based PDF File getting error:
java.net.SocketException: Software caused connection abort: recv failed in Result
The above error is coming for "driver.getWindowHandles()" method
It's working for Chrome and IE but when I'm using Gecko driver Version - 20.1, I'm able to Switching the Window Based PDF.
Can anyone help me with this?
I want to handle it by using latest gecko driver -21.0
Unfortunately, it is difficult to perform operations on pdf by switching tabs. The best way is to download the pdf and perform operations on the downloaded file using some java library or pdf-parser.
This usual behaviour of pdf is due to an enabled feature of pdf js. Disabling that in the firefox profile may solve your issue
Update your Firefox profile solves this issue.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "pdfjs.disabled", true );
profile.setPreference("pdfjs.disabled", true );
profile.setPreference("pdfjs.enabledCache.state", false );
profile.setPreference("pdfjs.enabledCache.state", false);
profile.setPreference("pdfjs.migrationVersion", 2);
profile.setPreference("pdfjs.previousHandler.alwaysAskBeforeHandling", true);
profile.setPreference("pdfjs.previousHandler.preferredAction", 4);
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
which stops the pdf opening in new window and further you can implement a method to download the file and parse the downloaded file.
Hope this helps you :)
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");
}
}
I am using Jmeter 2.13 alongside with a selenium webdriver plugin. When I start my thread it opens a new firefox session with all the cookies and cache cleared. In a previous session I have made a sync that lasts almost 5 minutes that brings me in my app some products. I don`t want to sync everytime I start the thread.
Is there any way I could start the new firefox session without clearing cookies/cache ?
If my guess is correct, that Selenium is the one that is opening an instance of Firefox, please see below. If not, please provide more info about what you have setup with code examples.
By default Selenium is opening the Firefox in Safe mode, where a lot of stuff are disabled (like extensions, localstore settings, etc). This also means that you won't have any cache or cookies.
You can read more about this here.
To disable this, you need to set the `toolkit.startup.max_resumed_crashes` setting key in in `about:config` to `-1`.
Selenium code wise, this can be achieved by setting the preference in the FirefoxProfile. C# code to achieve it would look like this:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("toolkit.startup.max_resumed_crashes", "-1");
IWebDriver driver = new FirefoxDriver(firefoxProfile);
Looking into FirefoxDriverConfig.java source code the plugin creates new profile each time Firefox starts:
FirefoxProfile createProfile() {
FirefoxProfile profile = new FirefoxProfile();
String userAgentOverride = getUserAgentOverride();
String ntlmOverride = getNtlmSetting();
if (StringUtils.isNotEmpty(userAgentOverride)) {
profile.setPreference("general.useragent.override", userAgentOverride);
}
if (StringUtils.isNotEmpty(ntlmOverride)) {
profile.setPreference("network.negotiate-auth.allow-insecure-ntlm-v1", true);
}
profile.setPreference("app.update.enabled", false);
addExtensions(profile);
setPreferences(profile);
return profile;
}
So there are 2 options:
Get plugin source code and amend profile initialisation line to use your existing profile as:
FirefoxProfile profile = new FirefoxProfile("/path/to/firefox/profile");
See How do I find my profile page of Mozilla documentation for instructions on how you can locate your current profile directory.
Stop using WebDriver Sampler and switch to JSR223 Sampler instead, it supports all the languages WebDriver Sampler does and provides full control (you'll have to write all the code to configure, start and stop browser yourself)