I'm using nightwatchjs (version 1.7x) to run my tests.
One of my tests is to test that an attribute contains one of a possible 2 values.
In the html below;
<iframe id="google_ads_iframe_/24156345/SMODAUTOMOTIVE/SMOD_Parkers/car-reviews/leaderboard-gallery/ReviewIntroduction_0" name="google_ads_iframe_/24156345/SMODAUTOMOTIVE/SMOD_Parkers/car-reviews/leaderboard-gallery/ReviewIntroduction_0" title="3rd party ad content" width="320" height="100" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" role="region" aria-label="Advertisement" tabindex="0" style="border: 0px; vertical-align: bottom;" data-google-container-id="7" data-gtm-yt-inspected-13="true" data-load-complete="true"></iframe>
And I need to test that if the width
attribute is a value of 320
, then the height
attribute can be either 100
or 200
.
So my code (snippet) is currently;
browser.getAttribute('#mpu-gallery iframe', 'width', function(adWidth) {
mpuWidth = adWidth.value;
})
browser.getAttribute('#mpu-gallery iframe', 'height', function(adHeight) {
mpuHeight = adHeight.value;
if (mpuWidth = '320') {
browser.assert.equal(mpuHeight, '100' || '200')
}
But this doesn't work, and produces an error of;
Failed [equal]: ('200' == '100') - expected "100" but got: "200"
If the the height value is 100
then the test passes, but if the height value is 200
the test fails.
It appears that the if
part of the code is only taking notice of the first assertion.
I also tried the following code,
if (mpuAdWidth = '300') {
browser.assert.equal(mpuAdHeight, '250')
} else if (mpuAdWidth = '300') {
browser.assert.equal(mpuAdHeight, '600')
}
but this didn't work either.
Any help would be greatly appreciated. Thanks.