Unable to clear Browser cookies and Session Data with Selenium - java

I have been using Java Selenium WebDriver along with Appium to perform tests on Mobile environment be it Emulator(Genymotion) or Physical devices (Android). I am using chromedriver, which I am using to perform tests on Web App in Chrome browser. I am looping my cases for multiple sets of data but the application requires a full browser Cookie and all Session data to be deleted before each loop starts.
I tried using driver.Manage().Deleteallcookies(), but it did not work out for me. I read in some threads to try creating a new session of the browser before each loop. So I tried driver.quit() but it ends the chromedriver session and ends the test. I also tried driver.close() but got the same results as driver.quit().
Can any one suggest a way to delete the browser cookies and session data in chrome browser??
My Appium version:1.3.4.1
Chromedriver version:2.3
Device/Emulator i am trying to test on : Nexus5/Samsung Note 3 Android:4.4.4/5.0

You can try using the following to ensure a clear session. Note I never tested that myself. My understanding is that selenium by default create a new session unless you specified something different or load a profile.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
ChromeDriver driver = new ChromeDriver(capabilities);

Related

Run selenium with cache on centos/linux

I'm able to run selenium on non GUI centos/linux machine in headless mode.
I have been trying to run it with cache enable by passing below chromeoptions arguments.
chromeOptions.addArguments("user-data-dir=~/.config/google-chrome");
It has started fine and identified elements till login page(which is first page) and couldn't identify any locators after that.
Is it the right approach to run cache enabled selenium run?
It's not that super clear when you mention about executing your tests with cache enabled. However, adding the argument user-data-dir is the canonical way to use a specific Chrome Profile.
You can find a couple of detailed discussions in:
How to open a Chrome Profile through Python
How to use Chrome Profile in Selenium Webdriver Python 3
Adding those options helps me to prevent crashes and errors on a linux remote machine
ChromeOptions options = new ChromeOptions();
options.addArguments(
"--disable-gpu",
"--headless",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--disable-extensions",
"--no-sandbox",
"--disable-dev-shm-usage",
"--hide-scrollbars",
"--allow-running-insecure-content",
"--disable-infobars",
"--ignore-certificate-errors");
Webdriver driver = new ChromeDriver(options);

Need help about webrtc performance test with Selenium and Jmeter (Java)

I am trying to automate test to webrtc application and I'm trying to do it with multiple users. I created a setUp as below.
`
ArrayList<String> prefs = new ArrayList<String>();
prefs.add("--use-fake-device-for-media-stream");
prefs.add("--use-fake-ui-for-media-stream");
System.setProperty("webdriver.chrome.driver", "C:\\....\\resources\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments(prefs);
driver = new ChromeDriver(options);
driver.get("https://......");`
but when I use "--use-fake-ui-for-media-stream", the following remote address appears in the logs of the media server of the app.(I used this to disable the security popup for camera and mic.)
remote address looks like: 79beeb9e-ff01-4e69-906c-5be9cab979e6
when I don't use it, the remote address looks like this: 172.17.x.x
Therefore, I cannot connect to the meeting room, the server refuses the remote address.
When I remove "--use-fake-ui-for-media-stream" and put "--user-data-dir=C:\Users....\Local\Temp\...", I overcome this problem, but this time I can only connect to a single chromedriver on the Jmeter, the other chromedrivers are not working. I integrated testcases to Jmeter with Junit request.
I want to use this code for multiple users but I only could do it for a user or I could not connected.
How can i overcome this problem?
When first ChromeDriver instance is launched the profile directory gets locked and it cannot be re-used by 2nd, 3rd, etc. instance.
You can do something like:
prefs.add("--profile-directory=User" + org.apache.jmeter.threads.JMeterContextService.getContext().getThreadNum());
so each instance will have it's own separate profile folder.
More information:
open multiple chrome profile with selenium
JMeterContextService JavaDoc
How to Use JUnit With JMeter

Selenium Basic Authentication via URL HeadlessChrome ( On Linux Server)

In my Selenium Tests I need to test a webpage where I use a basic Authen,
Knowing that I am using Chrome Headless Java and Selenium WebDriver.
On my machine 'locally' It works perfectly using driver.get("https://admin:admin#localhost..");
and then
driver.get("https://localhost..") for example.
I know that Chrome doesn't support this function anymore but I managed to make it work based on someone's solution here by passing the first URL with credentials and the second without.
But when I run it on remote (Jenkins) On Linux servers I get the following Error
the configuration of your browser does not accept cookies
. I don't have vision on the servers when I can configure Chrome ..any ideas how to make it work without facing that problem.
I know a lot of people asked that question before, But I didn't find any valide answer for my issue.
try ChromeDriver 2.45 (changelog) or change the location, where it is supposed to save the cookies:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
otherwise (per default) it would create a new temporary directory each time it starts a session.
ChromeOptions options = new ChromeOptions();
//Command line flag for enabling account consistency. The default mode is disabled.
options.addArguments("--account-consistency");
//Chrome that will start logging to a file from startup
options.addArguments("--log-net-log=C:/some_path/resource/log.json");
//Sets the granularity of events to capture in the network log.
options.addArguments("--net-log-capture-mode=IncludeCookiesAndCredentials");
Try this, basically, it saves the logs on startup of chrome browser, then it will set the account consistency. Anywhere from the log, you can debug the issue.
Hello I managed to fix the problem (I forgot to mention that our website is protected by Siteminder) so I did the following following:
1-We inject the USER and the PASSWORD on the URL :
The issue we faced was that the displayed prompt wasn’t part of the page’s HTML and it was hard for us to catch it using Selenium. We managed this by directly injecting the user login and the user password in the URL as follow :
‘https://USERNAME:PASSWORD#basicAuthentURL’
This will launch the Chrome session. Beware, this is only the first step of the process. The user identification have not been performed yet.
2- We create a new cookie :
After launching the URL, we have to manually create a cookie called « SMCHALLENGE » and add it to current session with Selenium, for example in JAVA :
new Cookie("SMCHALLENGE", "YES");
3- Call the URL without the user credencials :
As the SMCHALLENGE cookie is now set, the last step is to call the URL again (https://basicAuthentURL ). The SMCHALLENGE cookie will be deleted once the authentication succeed and a SMSESSION cookie will be generated by Siteminder.
The SMSESSION cookie now allows us to call the application and sucessfully pass Siteminder as if normally logged in (via SSO).
Let me know if you try this out.

Unable to sendkeys/click with selenium Java or JavascriptExecutor

These are the steps that my code is running.
I start the chromedriver with the secure shell appt - no issues, it launches the browser and appt correctly
chromeOptions.addExtensions(new File("src/test/resources/win32/browserprofile/Secure-Shell-App_v0.8.43.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
I then navigate using driver get to the chrome URL setup page to send connection data.
driver.get("chrome-extension://pnhechapfaindjhompbnflcldabbghjo/html/nassh.html");
While on this page from the image below, I tried to send keys or click on any of the fields with sendkeys or click and I get the following error.
I have tried multiple ways and im getting the same results: org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null
Here is my code
//Webdriver
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("aabb");
driver.findElement(By.id("field-username")).click();
driver.findElement(By.id("field-username")).sendKeys("useridval");
driver.findElement(By.id("field-hostname")).click();
driver.findElement(By.id("field-hostname")).sendKeys("10.0.0.0");
//JavascriptExecutor
// This will execute JavaScript in your script
((JavascriptExecutor)driver).executeScript("document.getElementById('field-username').value='migsrcrfuser';");
Question: Is this even possible, I see an id and the id is unique; furthermore, I also tried xpath and received the same result. Thoughts
Breift description: Terminal emulator and SSH client.
Secure Shell is an xterm-compatible terminal emulator and stand-alone ssh client for Chrome. It uses Native-Client to connect directly to ssh servers without the need for external proxies.
https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd
Update your ChromeDriver to 2.37 (the latest) from https://sites.google.com/a/chromium.org/chromedriver/downloads
I think that you are using Chrome v65
The issue was frame related. I used this code to identified how many frames and then send keys to the correct frame. phew!
int size = driver.findElements(By.tagName("iframe")).size();
System.out.println(size);
driver.switchTo().frame(1); // Switching the inner Frame with 1 0 for outer fram
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("9109");

In parallel execution, safari browser navigate to url with out login page automatically

I am using selenium web driver 2.48 and safari driver 2.48 and safari version 8.0.8
I am facing a problem on running my test execution in safari driver.The problem is
"In parallel execution, if in one safari window,login is successfull, than in other
safari windows, this login page is not shown,
that means safri navigate to url with
out login as one safari window already complete login."
and for this reason, i am facing below issue in parallel execution:
"CSRF verification failed.Request aborted"
I want like that for parallel execution:
if five safari browser window open, in each window, login page will be appeared.
In a sense, each safari driver instance will not share other safari driver
instances resources or any other thing
I have changed safari preferences settings but its not helping.
Is there any best way to declare safari driver or i need to add any desired capabilities or
any other things in safari preferences or any any good suggestion.
please and thanks.
i am using the following code:
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
DesiredCapabilities dc = DesiredCapabilities.safari();
dc.setCapability(SafariOptions.CAPABILITY, safariOptions);
currentDriver = new SafariDriver(dc);
Set<Cookie> cookies = currentDriver.manage().getCookies();
currentDriver.manage().deleteAllCookies();
if(!cookies.isEmpty())
{
Iterator<Cookie> iter= currentDriver.manage().getCookies().iterator();
while(iter.hasNext()){
Cookie C = iter.next();
}
cookies.clear();
}
I personally have not used safari before. And as you said that the behavior in all other browsers are as you expect it to be. I would like you to try the following.
There is a way by which you can specify the profile of the driver instance to be used. I would suggest you to create separate profiles for each instance and try out . How to do that is explained in this answer. This answer explains how to use same profile each time . You need to use a different profile each time. ( Which happens by default in chrome not sure why it wouldn't for safari )

Categories

Resources