Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a page object for the snippet generator #1492

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,6 +2,8 @@

import java.net.URL;

import org.openqa.selenium.By;

/**
* Page object for the system configuration page.
*
Expand Down Expand Up @@ -50,4 +52,11 @@ public void setQuietPeriod(int seconds) {
public void setDescription(String desc) {
control("/system_message").set(desc);
}

public String getHomeDirectory() {
ensureConfigPage();

return driver.findElement(By.xpath("//div[contains(text(), 'Home directory')]//..//*[@class='setting-main']"))
.getText();
}
}
@@ -0,0 +1,40 @@
package org.jenkinsci.test.acceptance.po;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

/**
* {@link PageObject} for the snippet generator to create bits of code for individual steps.
*/
public class SnippetGenerator extends PageObject {
private static final String URI = "pipeline-syntax/";

/**
* Creates a new page object for the snippet generator.
*
* @param context
* job context
*/
public SnippetGenerator(final WorkflowJob context) {
super(context, context.url(URI));
}

@Override
protected WorkflowJob getContext() {
return (WorkflowJob) super.getContext();
}

/**
* Generates the sample pipeline script.
*
* @return the generated script
*/
public String generateScript() {
WebElement button = find(By.id("generatePipelineScript-button"));
button.click();
elasticSleep(500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid introducing new POs with elastic sleep where they can be avoided.

if the callers are never going to call generate script more than once you can wait wait.until the textarea is not empty. (and add this fact to the javadoc)
if it is going to call it more than once with different options then it should be possible to get a before and wait until it is not the same.

WebElement textarea = find(By.id("prototypeText"));
return StringUtils.defaultString(textarea.getAttribute("value"));
}
}