Robotframework-browser httpcredentials uncreatable

I cannot create HttpCredentials in anyway including what the docs state:

New Context httpCredentials={‘username’: ‘admin’, ‘password’: ‘123456’}
ValueError: Direct assignment of values or variables as ‘httpCredentials’ is not allowed. Use special variable syntax ($var instead of ${var}) to prevent variable values from being spoiled.

${credentials} {‘username’: ‘username’, ‘password’: ‘pw’}
New Context httpCredentials=${credentials}

ValueError: Direct assignment of values or variables as ‘httpCredentials’ is not allowed. Use special variable syntax ($var instead of ${var}) to prevent variable values from being spoiled.

&{credentials}= username=un password=pw

ValueError: Direct assignment of values or variables as ‘httpCredentials’ is not allowed. Use special variable syntax ($var instead of ${var}) to prevent variable values from being spoiled.

versions:
robotframework-browser 16.0.0
robotframework 6.0.2 & 5.0.1

${credentials} Create Dictionary username=admin password=admin

ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.

Hi Judea,

Did you do this:

${credentials} Create Dictionary username=admin password=admin

or this:

${credentials}    Create Dictionary    username=admin    password=admin

The first one quite likely will give you the error you got, the second one will probably give you what you wanted.

Have a look at Space separated format in the documentation, take your time to read and understand this, it’ll likely save you a lot of pain in the future.

Dave.

${credentials}    Create Dictionary    username=admin 
   password=admin

New Context httpCredentials=${credentials}

I get this:

ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.

Hi Judea,

Ok try adding the equals (=) to ${credentials} like in the Create Dictionary documentation

    ${credentials}=    Create Dictionary    username=admin    password=admin

Dave.

that gives me: ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.

Hi Judea,

In my example it was

    ${credentials}=    Create Dictionary    username=admin    password=admin

not

 ${credentials}= Create Dictionary username=admin password=admin

White space is really important in Robot Framework → Space separated format:

When using the space separated format, the separator between tokens is two or more spaces or alternatively one or more tab characters.

The error you got indicates ${credentials} contains the string “Create Dictionary username=admin password=admin” not a dictonary, which is what happens when you only have a single space.

If you prefer you can also use the Pipe separated format like this:

|   | ${credentials}= | Create Dictionary | username=admin | password=admin

But I’m not sure if you can mix the formats in the same robot file, I wouldn’t recommend it anyway, this might help you to see when the separation is missing.

Personally I just use a space+tab combination (one of each) so they are always nicely separated.

Dave.

The white space is correct. I was just giving you the error message, plus this site cuts the white space out of my comments. Which is weird since whitespace is so important.

*** Settings ***
Library  Browser

*** Variables ***
${test_url}  https://google.com/
&{credentials} =    username=admin    password=admin

*** Test Cases ***

Wish this would work
    New Browser     chromium    headless=false
    Should Be True  ${credentials} == {'username': 'admin', 'password': 'admin'}
    New Context    httpCredentials=${credentials}  ignoreHTTPSErrors=${TRUE}

*** Keywords ***

Note that the dictionary gets created just fine, then still fails:
ValueError: Direct assignment of values or variables as ‘httpCredentials’ is not allowed. Use special variable syntax ($var instead of ${var}) to prevent variable values from being spoiled.

The below is the closest I have got. but gives me this:
ValueError: Direct assignment of values or variables as ‘httpCredentials’ is not allowed. Use special variable syntax ($var instead of ${var}) to prevent variable values from being spoiled.

Note that the dictionary gets created just fine, I know you are trying to pawn it off on that.

*** Settings ***
Library  Browser

*** Variables ***
${test_url}  https://google.com/
&{credentials} =    username=admin    password=admin

*** Test Cases ***

Wish this would work
    New Browser     chromium    headless=false
    Should Be True  ${credentials} == {'username': 'admin', 'password': 'admin'}
    New Context    httpCredentials=${credentials}  ignoreHTTPSErrors=${TRUE}

*** Keywords ***

Hi Judea,

That’s interesting, you’ve followed almost exactly what’s shown in the documentation,

The only difference I see is the extra space before the equals (&{credentials} =) in the variables section, that’s not used in the documentation, so you could try removing that space (&{credentials}=)

I wouldn’t have expected you to get that error, but you could also try doing as it says and use the $var syntax like this:

New Context    httpCredentials=$credentials  ignoreHTTPSErrors=${TRUE}

I’d be surprised if this works, but that is what it seems to be telling you? Everything else looks correctly formatted.

Dave.

Yeah I get the same error. Is this a versioning issue somehow?

Hi Judea,

Not sure, I’ve never encountered an issue with Browser Library, but I never needed to use this sort of authentication either.

What version do you have installed?

  • If it’s not the latest version (16.0.0), try updating to the latest version version (pip install -U robotframework-browser)
  • if you already have the latest version you could try going back a release and seeing if that fixes it (pip install robotframework-browser==15.2.0)

If you can confirm that you are having this issue on the latest version hopefully one of the developers of Browser library will jump in to help you.

Dave.

Hey everybody,

I also just encountered the same issue.
Before finding this thread, I also tried a lot and ended up with the same messages as mentioned by @dumontjudea2.
I even downgraded to 15.2.0, but it didn’t change anything.

Hope someone will find a solution here :slight_smile:

Guys, I got sucess with robotframework-browser==14.3.0.
I was with this same problem, solved when I returned to version 14.3.0.
The message stayed as WARN instead FAIL.

I hope that developers of Browser solve this problem in recent versions

2 Likes

Hi @dumontjudea2
same problem fixed for me following ‘Example as literal’ in the latest documentation bellow :

HttpCredentials (TypedDict)

Documentation

Sets the credentials for http basic-auth.

Can be defined as robot dictionary or as string literal. Does not reveal secrets in Robot Framework logs. Instead, username and password values are resolved internally. Please note that if enable_playwright_debug is enabled in the library import, secret will be always visible as plain text in the playwright debug logs, regardless of the Robot Framework log level.

Example as literal:

${pwd} = Set Variable 1234
${username} = Set Variable admin
New Context
… httpCredentials={‘username’: ‘$username’, ‘password’: ‘$pwd’}

Example as robot variable

***Variables ***
${username}= admin
${pwd}= 1234
${credentials}= username=$username password=$pwd

***Keywords ***
Open Context
New Context
… httpCredentials=${credentials}

Dictionary Structure

{
‘username’:
‘password’:
}

Converted Types

  • string
  • Mapping

Usages

  • New Context
  • New Persistent Context

src : Browser (marketsquare.github.io)