Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/layout/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,35 @@ span.xpassed,
}
}

.col-testId {
.copy-btn {
margin-left: 8px;
padding: 2px 4px;
border: $border-width solid #ccc;
border-radius: 3px;
background-color: transparent;
cursor: pointer;
font-size: $font-size-text;
line-height: 1;
vertical-align: middle;
transition: all 0.15s ease;

&:hover {
background-color: #f6f6f6;
border-color: #999;
}

&:active {
background-color: #e6e6e6;
}

&.copied {
background-color: #e6e6e6;
border-color: #999;
}
}
}

/*------------------
* 2. Extra
*------------------*/
Expand Down
4 changes: 3 additions & 1 deletion src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ def _process_report(self, report, duration, processed_extras):
]
cells = [
f'<td class="col-result">{outcome}</td>',
f'<td class="col-testId">{test_id}</td>',
f'<td class="col-testId">{test_id}'
f'<button class="copy-btn" data-test-id="{test_id}"'
f' title="Copy test ID" aria-label="Copy test ID">&#x1F4CB;</button></td>',
Comment thread
Ambuj03 marked this conversation as resolved.
Outdated
f'<td class="col-duration">{formatted_duration}</td>',
f'<td class="col-links">{_process_links(links)}</td>',
]
Expand Down
24 changes: 24 additions & 0 deletions src/pytest_html/resources/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const renderContent = (tests) => {
find('.logexpander', row).addEventListener('click',
(evt) => evt.target.parentNode.classList.toggle('expanded'),
)
const copyBtn = find('.copy-btn', row)
Comment thread
Ambuj03 marked this conversation as resolved.
Outdated
if (copyBtn) {
copyBtn.addEventListener('click', handleCopyTestId)
}
newTable.appendChild(row)
}
})
Expand All @@ -78,6 +82,21 @@ const renderContent = (tests) => {
table.replaceWith(newTable)
}

const handleCopyTestId = (evt) => {
evt.stopPropagation()
const button = evt.currentTarget
const testId = button.dataset.testId

navigator.clipboard.writeText(testId).then(() => {
button.classList.add('copied')
setTimeout(() => {
button.classList.remove('copied')
}, 500)
Comment thread
Ambuj03 marked this conversation as resolved.
Outdated
}).catch(() => {
// Silently fail if clipboard API unavailable
})
}

const renderDerived = () => {
const currentFilter = getVisible()
possibleFilters.forEach((result) => {
Expand Down
Loading