I am automating a application in selenium automation tool using java, with headless chrome.
My application needs OTP verification on first login in a computer or a new browser(chrome/mozila/IE). Once OTP verified on the machine or browser, from next time it will not request to enter OTP. Login is enough.
Since its headless browser which I am automating ,I thought I can give OTP and verify by entering OTP in console for first time and from next time it may not ask for OTP.
System.setProperty("webdriver.chrome.driver", constant.browserPathChrome);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
chromeOptions.addArguments("--enable-javascript");
chromeOptions.addArguments("--disable-gpu");
driver = new ChromeDriver(chromeOptions);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("my application url");
But chrome headless keep asking for OTP everytime, when I launch the site from same machine even after verifying it first time in my machine by providing the received OTP in console as input. But everytime I can not give OTP when automating. how to make it behave like other browsers? which capability I should add?
Phantom.js doesnt have this kind of issue, when I give OTP via console for the first time, it takes verifies and from next time it doesnt ask for OTP. but due to some other reasons I am not able to use pahntom.js. I want to use chrome headless.
Selenium will create a new instance of browser for each run, so it is valid that it asks OTP for each run.
One solution may be you can add a Chrome profile while initiating the browser instance, so that selenium will pick this profile instead of launching its default one.
chromeOptions.addArguments("user-data-dir=path_of_chrome_profile");
chrome profile path can be your local path or repository path
Related
My 'sign in' is in IE browser and after sign in if i click on the links they get opened in chrome browser. How to switch my current browser from IE to chrome during the same Test case. If i create a instance of chrome driver, it opens a new browser altogether and if i use getWindowHandles to get chrome browser count, it gives one. It didn't recognize the chrome browser opened by the IE browser. Please guide me.
I thought opening a new instance of chrome driver would solve my problem but it doesn't let me go to the session created through IE browser chrome browser.
As far as I know, you cannot do it with Selenium as the driver instance, once created, remains with the same browser until quit.
Firstly, have you set you default browser on PC as IE browser? In that case, the new links may also get opened with IE browser so handling windows/tabs would work.
I am trying to automate some scenario of a website which IP is blocked from my country.I can access the website and it's webelement through free VPN service which is an extension of chrome.After writing the code with webdriver and java when I want to verify the code through chrome driver instance then it unable to show the website content and show the IP block message.My question- is there any way to automate and open this IP block website with chrome driver instance?
I need particular code/steps so that i can follow the steps and eradicate my problem.
Thanks
I'm writting an automatied test with using selenium dirver and geckoDriver for mozilla firefox v56. The application which I'm testing always ask user to allow the camera usage and always this notification is displayed:
The problem is that, the Mozilla browser session which is created by geckoDriver does not saved settings where I always allow this page to use the camera driver.
I'm talking about this solution: https://support.mozilla.org/en-US/kb/firefox-page-info-window
I cannot find any parameter in about::config page which which I can run firefox to never ask about this permission again. Can I ask for your help?
I have search throughout the internet but none of the answers I found have a clear solution.
I am using selenium webdriver with Java.
My test needs to verify when you save your login information and close the browser and reopen it then those credentials remain and are saved on a new session. So I want to close the current session and reopen it in order to verify if a cookie persists on the page however Selenium deletes all stored session data so the test case will always fail. Is there any way to prevent Selenium from deleting the stored session data after closing the browser for the specific test case?
When I do run it I get a no such session error.
This solution works for chrome .
When you launch chrome (I think same applies for other browsers ) selenium creates a temporary profile and when you close it it deletes it. So when you relaunch the browser the new profile will not have the session information. What you can do is use profiles.
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:\\Users\\"+System.getenv("USERNAME")+"\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(desiredCapabilities);
This way if you create your driver, every time chrome will be launched with the same profile and if you dont do
driver.manage().deleteAllCookies();
Your session information will persist in the new session of chrome driver. If you dont want it to persist you can clean the cookies using the above command or just simple log out. This should solve your problem. Similar things should also be possible in other browsers.
To know which profile is currently used type chrome://version/ in your address bar it has the information of the current profile being usesd. To know more about see this
I am trying to use Selenium 2.0 (Webdriver) to implement a series of tests. Before these tests can run, I have to login into the application. Since the application is not my 'own' (testing api-built functionality), each test should not be logging into my application to run.
I would prefer to do the following:
Connect my webdriver tests to my open Firefox browser (already loggedin)
Run my webdriver projects with the same browser.
I understand that Selenium usually assigns a session id to its browsers. However, the current Java implementation of Selenium 2.0 driver does not make use of session id (maybe it does but I don't know where to find it. )
Can someone provide some direction on how to resolve my issue (existing browser and run multiple tests with Selenium 2.0 (java))? Any code provided would also be helpful. Thanks!
Here is what I have learnt:
Selenium 1: As Ioan suggested earlier, use "-firefoxProfileTemplate" when starting up the Selenium RC server and point to the location of your Firefox profile.
Selenium 2: I suppose you can use the Selenium 1 RC server, however, since Selenium 2 uses WebDriver, you can point to the profile information within your code.
File profileDir = new File("/Users/_____/selenium/FFprofile");
FirefoxProfile profile =
new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(
profile);
Notes:
Make sure you run "firefox -profilemanager" to create your initial profile and save your login information.
Allow the browser/website to always store your authentication credentials avoiding "popup"/"login" wwindows, etcs.
Hope this helps somebody who may run into a similar issue: Using the same browser profile in Selenium, etc.