Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automated_testing_kit_d7
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
automated_testing_kit_d7
Commits
3dfaa384
Commit
3dfaa384
authored
11 months ago
by
André Angelantoni
Browse files
Options
Downloads
Patches
Plain Diff
Update
PW-1130
in atk_media.spec.js.
parent
860ec28f
Branches
1.0.x
No related tags found
1 merge request
!12
Update PW-1130 in atk_media.spec.js.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
playwright/e2e/atk_entity/atk_media.spec.js
+26
-35
26 additions, 35 deletions
playwright/e2e/atk_entity/atk_media.spec.js
with
26 additions
and
35 deletions
playwright/e2e/atk_entity/atk_media.spec.js
+
26
−
35
View file @
3dfaa384
...
@@ -8,23 +8,20 @@
...
@@ -8,23 +8,20 @@
/** ESLint directives */
/** ESLint directives */
/* eslint-disable import/first */
/* eslint-disable import/first */
import
*
as
atkCommands
from
'
../support/atk_commands
'
;
import
*
as
atkUtilities
from
'
../support/atk_utilities
'
;
// Set up Playwright.
// Set up Playwright.
const
{
test
,
expect
}
=
require
(
'
@playwright/test
'
);
const
{
test
,
expect
}
=
require
(
'
@playwright/test
'
);
import
playwrightConfig
from
'
../../playwright.config
'
;
import
playwrightConfig
from
'
../../playwright.config
'
;
const
baseUrl
=
playwrightConfig
.
use
.
baseURL
;
const
baseUrl
=
playwrightConfig
.
use
.
baseURL
;
// Import ATK configuration.
// Import ATK Libraries and configuration.
import
*
as
atkCommands
from
'
../support/atk_commands
'
;
import
*
as
atkUtilities
from
'
../support/atk_utilities
'
;
import
atkConfig
from
'
../../playwright.atk.config
'
;
import
atkConfig
from
'
../../playwright.atk.config
'
;
// Holds standard accounts that use user accounts created
// Holds standard accounts that use user accounts created
// by QA Accounts. QA Accounts are created when the QA
// by QA Accounts. QA Accounts are created when the QA
// Accounts module is enabled.
// Accounts module is enabled.
import
qaUser
Account
s
from
'
../data/qaUsers.json
'
;
import
qaUsers
from
'
../data/qaUsers.json
'
;
test
.
describe
(
'
Media tests.
'
,
()
=>
{
test
.
describe
(
'
Media tests.
'
,
()
=>
{
//
//
...
@@ -36,52 +33,44 @@ test.describe('Media tests.', () => {
...
@@ -36,52 +33,44 @@ test.describe('Media tests.', () => {
const
image2Filepath
=
'
tests/data/SmokeTest.png
'
;
const
image2Filepath
=
'
tests/data/SmokeTest.png
'
;
const
uniqueToken1
=
atkUtilities
.
createRandomString
(
6
);
const
uniqueToken1
=
atkUtilities
.
createRandomString
(
6
);
const
uniqueToken2
=
atkUtilities
.
createRandomString
(
6
);
const
uniqueToken2
=
atkUtilities
.
createRandomString
(
6
);
let
textContent
=
''
;
// Log in with the administrator account.
// Log in with the administrator account.
// You should change this to an account other than the administrator,
// You should change this to an account other than the administrator,
// which has all rights.
// which has all rights.
await
atkCommands
.
logInViaForm
(
page
,
context
,
qaUser
Account
s
.
admin
);
await
atkCommands
.
logInViaForm
(
page
,
context
,
qaUsers
.
admin
);
//
//
// Add an image.
// Add an image.
//
//
await
page
.
goto
(
baseUrl
+
atkConfig
.
imageAddUrl
);
await
page
.
goto
(
baseUrl
+
atkConfig
.
mediaAddUrl
);
textContent
=
await
page
.
content
();
expect
(
textContent
).
toContain
(
'
Media browser
'
);
// Upload image.
// Upload image.
await
page
.
setInputFiles
(
'
#edit-field-media-image-0-upload
'
,
image1Filepath
);
await
page
.
setInputFiles
(
'
[name="files[upload]"]
'
,
image1Filepath
);
const
altField
=
page
.
locator
(
'
input[name="field_media_image[0][alt]"]
'
);
await
page
.
click
(
'
#edit-next
'
);
await
altField
.
fill
(
`
${
testId
}
:
${
uniqueToken1
}
`
);
// Fill in as many fields as you need
// Fill in as many fields as you need
// if you've customized your media entity.
// if you've customized your media entity.
const
altField
=
page
.
locator
(
'
#edit-field-file-image-alt-text-und-0-value
'
);
// Uncomment to unpublish.
await
altField
.
fill
(
`
${
testId
}
:
${
uniqueToken1
}
`
);
const
publishInput
=
page
.
locator
(
'
input[name="status[value]"]
'
);
// eslint-disable-line no-unused-vars
// await publishInput.uncheck()
// Then save the entity.
// Then save the entity.
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Save
'
}).
click
();
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Save
'
}).
click
();
// We are now on the media content list. Confirm the image
// Extract the media id from the page URL.
// was rendered by checking for the token.
const
url
=
page
.
url
();
let
imageLocator
=
page
.
locator
(
`img[alt*="
${
uniqueToken1
}
"]`
);
const
match
=
url
.
match
(
/fid=
(\d
+
)
/
);
await
expect
(
imageLocator
).
toBeVisible
();
expect
(
match
).
toBeTruthy
();
const
mid
=
match
[
1
];
// Confirm image downloads correctly by testing the naturalWidth
// and NaturalHeight properties.
let
isImageDownloaded
=
await
imageLocator
.
evaluate
((
img
)
=>
img
.
naturalWidth
>
0
&&
img
.
naturalHeight
>
0
);
// Extract the media id that was added by
// automated_testing_kit_preprocess_image().
const
mid
=
await
imageLocator
.
getAttribute
(
'
data-media-id
'
);
//
//
// Update the media.
// Update the media.
//
//
const
mediaEditUrl
=
atkConfig
.
mediaEditUrl
.
replace
(
'
{mid}
'
,
mid
);
const
mediaEditUrl
=
atkConfig
.
mediaEditUrl
.
replace
(
'
{mid}
'
,
mid
);
await
page
.
goto
(
baseUrl
+
mediaEditUrl
);
await
page
.
goto
(
baseUrl
+
mediaEditUrl
);
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Remove
'
}).
click
();
await
page
.
setInputFiles
(
'
[name="files[replace_upload]"]
'
,
image2Filepath
);
await
page
.
setInputFiles
(
'
input[name="files[field_media_image_0]"]
'
,
image2Filepath
);
await
altField
.
fill
(
`
${
testId
}
:
${
uniqueToken2
}
`
);
await
altField
.
fill
(
`
${
testId
}
:
${
uniqueToken2
}
`
);
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Save
'
}).
click
();
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Save
'
}).
click
();
...
@@ -91,18 +80,20 @@ test.describe('Media tests.', () => {
...
@@ -91,18 +80,20 @@ test.describe('Media tests.', () => {
// We are back again on the media content list. Confirm the image
// We are back again on the media content list. Confirm the image
// was rendered by checking for the token.
// was rendered by checking for the token.
imageLocator
=
page
.
locator
(
`img[alt*="
${
uniqueToken2
}
"]`
);
const
imageLocator
=
page
.
locator
(
'
.content img
'
);
await
expect
(
imageLocator
).
toBeVisible
();
await
expect
(
imageLocator
).
toBeVisible
();
// Confirm image downloads correctly by testing the naturalWidth
// Confirm image downloads correctly by testing the naturalWidth
// and NaturalHeight properties.
// and NaturalHeight properties.
isImageDownloaded
=
await
imageLocator
.
evaluate
((
img
)
=>
img
.
naturalWidth
>
0
&&
img
.
naturalHeight
>
0
);
// eslint-disable-line no-unused-vars
const
isImageDownloaded
=
await
imageLocator
.
evaluate
((
img
)
=>
img
.
naturalWidth
>
0
&&
img
.
naturalHeight
>
0
);
// eslint-disable-line no-unused-vars
expect
(
isImageDownloaded
).
toBeTruthy
();
//
//
// Delete the media entity.
// Delete the media entity
; Delete button is on the edit page
.
//
//
const
mediaDeleteUrl
=
atkConfig
.
mediaDeleteUrl
.
replace
(
'
{mid}
'
,
mid
);
await
page
.
goto
(
baseUrl
+
mediaEditUrl
);
await
page
.
goto
(
baseUrl
+
mediaDeleteUrl
);
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Delete
'
}).
click
();
expect
(
await
page
.
content
()).
toContain
(
'
Are you sure
'
);
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Delete
'
}).
click
();
await
page
.
getByRole
(
'
button
'
,
{
name
:
'
Delete
'
}).
click
();
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment