protractor icon indicating copy to clipboard operation
protractor copied to clipboard

[BUG] deleteAllCookies() does not work

Open kms-loantran opened this issue 9 years ago • 6 comments

Bug Report:

Node Version: 8.1.4, 6.9.1, 6.9.2 Protractor Version: 5.1.2 Angular Version: non-angular but react Browser(s): chrome 59.0 Operating System and Version: wins10 Description:

I used browser.manage().deleteAllCookies() to delete all cookies after each test case but this function does not work. I already checked cookies of the browser and see that _ga and _gid still exist. This is why browser cannot display login page before each test case.

Here is my script:

describe('test suite', () => { beforeEach(async (done) => { await objLogin.launchLoginToCount(); await browser.sleep(15000); done(); });

afterEach(async(done) => {
  await browser.manage().deleteAllCookies();
  await browser.executeScript('window.sessionStorage.clear();');
  await browser.executeScript('window.localStorage.clear();');
  done();
})

it(' test case 1', async (done) => {
  //commands
  done();
});

it('test case 2', async (done) => {
  //commands
  done();
});

})

kms-loantran avatar Jul 23 '17 04:07 kms-loantran

Hi @kms-loantran ,

I've tried a simple script

describe('delete coockies on react site', () => {

    beforeEach((done) => {
        browser.driver.get('https://react.rocks/');
        done();
    })

    afterEach((done) => {
        browser.manage().getCookies()
            .then((cookies) => {
                console.log('cookies before delete = ', cookies);
                browser.manage().deleteAllCookies();
            })
            .then(() => browser.manage().getCookies())
            .then((cookies) => {
                console.log('cookies after delete = ', cookies);
                done();
            })
    });

    it(' test case 1', (done) => {
        //commands
        done();
    });

    it('test case 2', (done) => {
        //commands
        done();
    });
});

And I get this logging

npm run test.example

> [email protected] test.example /Users/wswebcreation/contributions/protractor
> node ./bin/protractor example/conf.js

[08:24:41] I/launcher - Running 1 instances of WebDriver
[08:24:41] I/local - Starting selenium standalone server...
[08:24:42] I/local - Selenium standalone server started at http://192.168.1.21:57316/wd/hub
Started
cookies before delete =  [ { path: '/',
    domain: '.react.rocks',
    name: '_gat',
    httpOnly: false,
    expiry: 1500791143,
    hCode: 2932251,
    secure: false,
    value: '1',
    class: 'org.openqa.selenium.Cookie' },
  { path: '/',
    domain: '.react.rocks',
    name: '_ga',
    httpOnly: false,
    expiry: 1563863083,
    hCode: 94585,
    secure: false,
    value: 'GA1.2.1160664121.1500791084',
    class: 'org.openqa.selenium.Cookie' },
  { path: '/',
    domain: '.react.rocks',
    name: '_gid',
    httpOnly: false,
    expiry: 1500877483,
    hCode: 2932483,
    secure: false,
    value: 'GA1.2.1586630014.1500791084',
    class: 'org.openqa.selenium.Cookie' } ]
cookies after delete =  []
.cookies before delete =  [ { path: '/',
    domain: '.react.rocks',
    name: '_gat',
    httpOnly: false,
    expiry: 1500791144,
    hCode: 2932251,
    secure: false,
    value: '1',
    class: 'org.openqa.selenium.Cookie' },
  { path: '/',
    domain: '.react.rocks',
    name: '_ga',
    httpOnly: false,
    expiry: 1563863084,
    hCode: 94585,
    secure: false,
    value: 'GA1.2.1751280520.1500791084',
    class: 'org.openqa.selenium.Cookie' },
  { path: '/',
    domain: '.react.rocks',
    name: '_gid',
    httpOnly: false,
    expiry: 1500877484,
    hCode: 2932483,
    secure: false,
    value: 'GA1.2.1113895178.1500791084',
    class: 'org.openqa.selenium.Cookie' } ]
cookies after delete =  []
.


2 specs, 0 failures
Finished in 0.905 seconds

[08:24:44] I/local - Shutting down selenium standalone server.
[08:24:44] I/launcher - 0 instance(s) of WebDriver still running
[08:24:44] I/launcher - chrome #01 passed

And it seems to work for me. The only difference is that I don't have the async / await in my script, but that should not be the problem I think. Do you have an example repo where we can test this.

wswebcreation avatar Jul 23 '17 06:07 wswebcreation

Hi @wswebcreation, Thanks for your reply. I've tried to get cookies and print it before deleting it as your way. The result I see is that cookies is empty when priting out, but the browser still keep the cookies inside. I script to ask brwoser wait for me in 45 seconds so that I can check its cookies. After pressing F12 to open Dev tool, I navigate to Application tab and I still see _ga and _gid available under Cookies section. The browser I'm using is 59.0.3071. Btw, 'await' keyword is to ask the promise to be finished first, then then next command will be called.

kms-loantran avatar Jul 23 '17 07:07 kms-loantran

Hi @kms-loantran

I made a typo in my comment, it should have been The only difference is that I don't have the async / await in my script, but that should not be the problem I think. I changed it ;-)

When I run the script, put sleep()s in it I get this. So it looks like it's working fine. Is an example repo an option? Could it also be that the logon part in your app is always resetting the cookies?

image

wswebcreation avatar Jul 23 '17 07:07 wswebcreation

Hi @wswebcreation, Cool! I guess this is a bug in our site. I've just tried to delete all cookies manually and hit F5 to refresh the page but cookies are still kept. Thanks a lot for your support :)

kms-loantran avatar Jul 23 '17 07:07 kms-loantran

I think the refresh will add them by default, that's also what the example site I used does. So I don't think it's a good example to proof the bug in your site.

For now I'm going to close this issue. If you still experience issues then re-open this issue and please provide an example project.

wswebcreation avatar Jul 23 '17 07:07 wswebcreation

Same issue solved https://stackoverflow.com/a/52214958/1356559

Amr1977 avatar Sep 07 '18 03:09 Amr1977