Normaly you are using selenium to automate testcases and after the testcase finished running, the browser closes.
However I try to use selenium webdriver to script specific tasks, e.g. login to a specific page but the browser should stay open after it.
I need the browser to stay open, because I developed a CMS where you can define selenium tasks and execute them. One of the tasks is to login to a backend, but I need to keep the website open forever, so that I can work in the backend. Problem: after about 20 minutes or so the browser which opened by starting the testcase, closes again.
I developed the portal so that I don't have to login to all my backends if I start working at the morning, I only have to login once into my portal and from there I can trigger everything I need.
I do it like this to login to typo3 backend (snippet):
$username_field = $SeleniumObj->byId('t3-username', true);
$pw_field = $SeleniumObj->byId('t3-password', true);
$submitButton = $SeleniumObj->byId('t3-login-submit', true);
$username_field->sendKeys("myusername");
$pw_field->sendKeys("mypasswd");
$submitButton->click();
exit;
You can see that I call exit at the end so that the "testcase" ends and the page stays open.
How to set the browser lifetime to infinite?
NOTES: I am using the latest selenium and facebook php-webdriver with custom code wrappers.
Testcase is to login to specific page.So, after using login credentials once login to specific page successfully, then testcase ends there.
Remove exit & see.
Related
I am running testcafe tests on an authentication page and I can see that testcafe is modifying/removing/adding the headers when sending the requests to the website and this is blocking me to do 2FA on this page
As soon as I got the issue, I tried to do the automation with Selenium just to confirm it is testcafe issue. As selenium doesn't create a proxy to insert the js scripts and automate the website I could do the automation with selenium, but I want to use testcafe as the site is developed in react.
await t.typeText(this.emailInput, config.userEmail)
.click(this.nextButton)
.typeText(this.passwordInput, config.userPassword)
.click(this.nextButton)
.click(this.otpOption)
.typeText(this.otpInput, this.token)
.click(this.signinButton)
}
When clicking on the next button I should have the 2FA form asking for the code, but I got a page saying was not possible to do the authentication (Something wrong happened) and I saw the response code for the BeginAuth endpoint was 222 without any response instead of 200.
The URL is that I am using to authenticate looks like this one:
https://login.microsoftonline.com/client uuid/oauth2/authorize?response_type=code%20id_token&response_mode=form_post&client_id=client uuid&scope=openid&x-client-Ver=4.0.0
Testcafe team found out this is a bug on testcafe-hammerhead, they have fixed and it is going to be included in the next release.
https://github.com/DevExpress/testcafe-hammerhead/issues/2052
For now I am generating the cookie in the automation and sending it in the header.
While automating with selenium if a username and password is entered why doesn't
chrome browser show the option to save credentials as it does in regular
practice.
As mentioned in previous answer, new instance of WebDriver opens fresh browser window, without previous cookies etc.
What could you do is:
When you first start WebDriver and open login page, using selenium enter credentials, make sure you check "remember details" checkbox is present.
Now once you are logged in, you can get cookies from browser using:
driver.manage().getCookies();
You could get all cookies and save them in text file for example.
Next time you open fresh browser, before opening page, load cookies that you previously saved.
driver.manage().getCookies().add(cookie);
Because of the way the web-driver works, it deletes all cookies/caches of information which could accidentally fail a test, you'll notice it doesn't open an ordinary browser, its often a light-weight version of the browser.
If you want it to save cookies and caches you will A) have to specify this in your code, and B) you will have to test around the fact that you have saved passwords, so if you move your tests onto a different computer, the browsers cache will be different and your tests won't work anymore.
Actually The Webdriver Opens The Browser Without Cookies. if You Need To Save Your cookies,you can use these commands,
driver.manage().getCookieNamed(String arg);
driver.manage().getCookies();
driver.manage().getCookies().add(cookie);
All Three are use to Get The Cookie and Save The Cookie.
or
if The Browser Shows a Pop-up,to Save The User name name and Password use can use This,
var options = new ChromeOptions();
options.AddArguments("chrome.switches", "--disable-extensions --disable-extensions-file-access-check --disable-extensions-http-throttling --disable-infobars --enable-automation --start-maximized");
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
var driver = new ChromeDriver(options);
I have a suite of three test cases to be run in selenium webdriver.
First and third test case requires a login whereas the second does not.
When I run the suite,it asks for the username and password,performs the first test case and then second test case runs in which the login is not required.It is actually a pre login test.After this when the third login starts it doesnt ask me to login again(the second test case should have ideally logged it out)..it instead takes the login credentials I provided in the start.
How is this happening?
if you have not logged out and the session has not timed out, there should be no reason for your application to ask for login credentials. You should ideally be logging out after each test so all tests are independent of each other.
you can use the below link to achieve this
Maintain and re-use existing webdriver browser instance - java
Or if you are using TestNG you can use ITestContext where you put the driver in context which you can use in 3rd test case so that you will get the session.
Currently I am working on some Automation testing on Salesforce using Selenium webdriver.Salesforce system asks for a two step verification code(mobile/email OTP) apart from the usual credentials.Now, once you verify the user with the OTP, the application supposedly saves it in the cookies. So, from next instances only user id-pwd combination is sufficient to logon.
So, for that I have created a custom profile in firefox and tried to launch it through my code.But each time I am running it, a new temp profile is getting created where the cookie details are not saved already.
This is the snippet of the code:
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("SFDC");
WebDriver driver = new FirefoxDriver(profile);
When I am trying to log in manually this(2 step verification) is not happening.The automated execution was working properly before 27th Jan.
Can you please help?
You might want to look at this post in the Salesforce Stack Exchange: https://salesforce.stackexchange.com/questions/107027/selenium-testing-two-factor-authentication-problems/107368
There they have a solution where you can disable the 2-factor authentication by white-listing your IP in Salesforce. It worked for me.
The AUT contains the login page which validates the user credentials. Once successful, the user needs to hit a new URL in a new tab to access the actual application.
Is it possible to automate the above scenario using selenium RC?
Yes it's possible, but I'd recommend using Selenium WebDriver as it's the current version. Selenium RC is very old.
Using Selenium WebDriver:
driver.navigate().to("http://aut/login");
driver.... // login logic like setting the user/pass clicking login.
...
driver.navigate().to("http://somenewurl.com");
// continue testing here...
If you are adamant on remaining with Selenium 1 (which i could understand if you already have a big suite in it..):
selenium.open("http://aut/login");
selenium... // login logic here
...
selenium.open("http://somenewurl.com");
// continue testing here.