GithubHelp home page GithubHelp logo

Comments (18)

monolithed avatar monolithed commented on May 21, 2024 1

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.

christian-bromann avatar christian-bromann commented on May 21, 2024

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.

tunix avatar tunix commented on May 21, 2024

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.

christian-bromann avatar christian-bromann commented on May 21, 2024

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.

tunix avatar tunix commented on May 21, 2024

@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.

tunix avatar tunix commented on May 21, 2024

@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.

christian-bromann avatar christian-bromann commented on May 21, 2024

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.

christian-bromann avatar christian-bromann commented on May 21, 2024

@tunix
Did it work? If so, I can close this issue

from webdriverio.

tunix avatar tunix commented on May 21, 2024

@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.

christian-bromann avatar christian-bromann commented on May 21, 2024

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.

monolithed avatar monolithed commented on May 21, 2024

@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.

christian-bromann avatar christian-bromann commented on May 21, 2024

@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.

monolithed avatar monolithed commented on May 21, 2024

@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.

anshulsahni avatar anshulsahni commented on May 21, 2024

does setting singleton as true in wdio config file still works? I can't find anything related to that in documentation

from webdriverio.

christian-bromann avatar christian-bromann commented on May 21, 2024

@tunix why do you still need this?

from webdriverio.

anshulsahni avatar anshulsahni commented on May 21, 2024

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.

christian-bromann avatar christian-bromann commented on May 21, 2024

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.

tunix avatar tunix commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.