How to convert #ffffff
to #fff
or #fff
to #ffffff
for Assertion?
I am using getCssValue("background")
from Selenium which returns rgb(255, 255, 255)
which I can split into:
- r ->
255
- g ->
255
- b ->
255
The following line of code:
String hex = String.format("#%02x%02x%02x", r, g, b);
Converts rgb to hex and gives an output as:
#ffffff
But from the console, the background is extracted as #fff
So what can be the ideal way either to:
- convert
#ffffff
to#fff
- convert
#fff
to#ffffff
I have been through a couple of relevant discussions as:
- Why use #fff color on body? which mentions that the issue is somewhat subjective.
- CSS: Which is faster for the browser? color:#fff; or color:#ffffff; which mentions CSS compressors will intelligently optimize to the #fff version.
But my tests are failing and there is a need for conversion. Any recommendations?