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.
ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.
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.
ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.
that gives me: ValueError: Argument ‘httpCredentials’ got value ‘Create Dictionary username=admin password=admin’ that cannot be converted to HttpCredentials or None.
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.
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.
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 ***
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.
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.
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
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’}