Comments (18)
After some time, I realized that using persistent session is not so good idea, but It can be implemented (as you please).
@tunix, it's important to encapsulate your data and avoid any side-effects. The state of your interface should not be kept after each test.
Real-world experience shows that you should have a simple Account service to create or get new sessions. Of course, you can have reusable accounts (in my practice, we have about 9 000 such accounts). But these accounts should be locked for parallel testing and cleaned / reseted after each test.
For example, my Account service can work with different schemes like new registered and reusable accounts. We also implemented different types of verification like Basic, OAuth and Multi-factor authentication.
I hope you will reconsider your testing practices and existing architecture.
from webdriverio.
I think this is already possible, just still not documented. I will fix this leak of documentation in the next version. Here is how you can do this:
in your first test file create a webdriverjs instance with the singleton option
client = webdriverjs.remote({singleton:true,desiredCapabilities:capabilities});
client
.init()
.url(testpageURL)
...
in the other files you just grab the singleton:
client = webdriverjs.remote({singleton:true});
client
.url(testpageURL)
...
If I understand you correctly, this should keep the session for your authentication required tests. You find the implementation of the singleton option here.
from webdriverio.
Hello @christian-bromann, I tried passing sessionId into desiredCapabilities. It's not documented as well but seems like if you define it, it's set as an attribute to WebDriverJS class. However I couldn't get it to work. I'll try the passing singleton, thanks!
from webdriverio.
With my approach you can use the same sessionId over several test files. Once you are authenticated you remain it. Are you saying you would like to use an already existing sessionID?
from webdriverio.
@christian-bromann - actually first thing you mentioned is what I want.. However being able to use an existing session id is also what I want because login procedure takes too much time (i don't know why but it takes too much time -- 4 seconds to 30+ seconds -- in selenium while taking seconds in the browser)
from webdriverio.
@christian-bromann - unfortunetely they don't seem to share the same client despite i added singleton to options. when i opened up verbose mode, i see that the server sets session and destroys it when a test is over.
from webdriverio.
If you are using webdriverjs in singleton mode dont call the end() function at the end of each test. This destroys the current session.
from webdriverio.
@tunix
Did it work? If so, I can close this issue
from webdriverio.
@christian-bromann - it worked when i made some slight modifications to my tests (each were requiring client.js seperately which led them to have different clients). Now the question is: is it possible to reuse an existing session in tests without needing to login each time test suite runs?
from webdriverio.
Actually no! There is no option to reuse an existing session ID. The problem is that the selenium standalone server cleans open sessions after a while (I think every 5 minutes). The only way to avoid logins is using cookies. The next version will support this binding. I hope a will get together a final release version next week.
from webdriverio.
@christian-bromann, It seems I have the same problem.
{
capabilities: [
{
browserName: 'firefox',
specs: [
'tests/get_session.js',
'tests/use_session.js',
...
]
}
]
};
How to keep the session for my authentication required tests with test-runner?
from webdriverio.
@monolithed if you use the test runner you don't need to create or end the session. It does that for you! In your case you should have the same session within both spec files
from webdriverio.
@christian-bromann, you absolutely right, thanks!
1st test
// auth/regular.js
let config = require('./config');
module.exports = () => {
return browser.url('/user/login')
...
};
// auth/index.js
module.exports = type => {
describe('Auth', () => {
it(type, () => require('./auth/' + type)());
});
};
2nd test
describe('Auth', () => {
it(type, () => require('./auth/' + type)());
});
It seems I lost context (browser
)
from webdriverio.
does setting singleton as true in wdio config file still works? I can't find anything related to that in documentation
from webdriverio.
@tunix why do you still need this?
from webdriverio.
For every spec it is running a different opens a new session of browser After I login test it should successfully run tests which require authentication but it doesn't
from webdriverio.
if you run the wdio test runner you can't avoid that. I would recommend to create some page that logs you in automatically and is only reachable in your test environment or write all tests in a single spec where you login first
from webdriverio.
Hi All,
A lot has passed since I've created this issue. I'm no longer interested in it as I can't even remember which project I asked this for. Thank you for all the efforts you've put in this issue!
from webdriverio.
Related Issues (20)
- [π‘ Feature]: Timeout for Entirety of WebDriverIO Test Runner Instance HOT 2
- [π Bug]: have a switch to allow offline mode, and donβt check chrome labs when not using chrome HOT 5
- [π Bug]: Cannot command on elements coerced into an array: `Malformed type for "elementId" parameter` HOT 2
- [π Bug]: Is the gitpod environment broken? HOT 2
- [π Bug]: @wdio/junit-reporter - Both Errors and Failures Incremented for Failed Tests HOT 2
- [π Bug]: touchAction exec error ( [email protected] ) HOT 1
- [π Bug]: Chrome temporary profile left on disk HOT 5
- [π Bug]: Mocha Step Definition Timeout HOT 4
- [π Bug]: custom element commands doesn't work with browser runner HOT 7
- [π Bug]: TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function HOT 3
- [π‘ Feature]: Centralized context manager for Iframe lookups HOT 1
- [π‘ Feature]: Support configuring NODE_OPTIONS for ChromeDriver separately from NODE_OPTIONS for WDIO itself HOT 5
- [π Bug]: I should be able to chain element using both xpath and css HOT 1
- [π Bug]: "goog:chromeOptions" args and prefs are being ignored? HOT 3
- [π Bug]: <Tough all the test cases of my spec files are passed it shows 1 spec failure in the console log> HOT 4
- [π‘ Feature]: Allow skipping anywhere in test execution HOT 5
- @wdio/runner: Error: Cannot find module HOT 1
- ERROR @wdio/runner: Error: Cannot find typescript module imported from spec.ts HOT 1
- [π Docs]: v8.36.0 tag and GitHub release points to wrong commit, v8.36.1 release notes are wrong HOT 1
- [π Bug]: isElementDisplayed returns incorrect result for elements with overflow-x/y: hidden and zero width/height HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webdriverio.