admin管理员组文章数量:1122832
I have a HTML front-end page with various buttons (different application names) on them. The way it should work is that when a user clicks on one button, it will launch the individual URLs in the Scenario Outline examples and a screenshot is taken of that page and saved to some location. I have completed the Java code and BDD for this load page and screenshot/save function.
The part I need assistance with, is the button click trigger, i.e. when the user clicks on button A or B or C do (above logic).
Because there are multiple buttons on the front-end, how can I write the Java function behind the BDD scenario to check which button the user clicks, so it redirects to the appropriate pages (using examples in scenario outline).
Below is an idea of what I am trying to achieve, but I am open to any alternatives.
@When user clicks on {string} then webdriverAgent opens {url}$
public boolean checkifbuttonisclicked(String xpath, String url) throws exception {
// if (driver.findElement(By.xpath(xpath)).Click()) {
//}
if (driver.findElement(By.xpath(xpath)).isSelected()) {
TakeaScreenshotofDesktop(app, yr); //separate function responsible for the screenshot
}
}
So basically,
Scenario Outline:
Load HTML Page (with multiple buttons)
When user clicks on <button>
Open <url> corresponding to the app in the example below
Examples
button | url
App1 | |
App1 | |
App1 | |
App2 | |
App2 | |
I have a HTML front-end page with various buttons (different application names) on them. The way it should work is that when a user clicks on one button, it will launch the individual URLs in the Scenario Outline examples and a screenshot is taken of that page and saved to some location. I have completed the Java code and BDD for this load page and screenshot/save function.
The part I need assistance with, is the button click trigger, i.e. when the user clicks on button A or B or C do (above logic).
Because there are multiple buttons on the front-end, how can I write the Java function behind the BDD scenario to check which button the user clicks, so it redirects to the appropriate pages (using examples in scenario outline).
Below is an idea of what I am trying to achieve, but I am open to any alternatives.
@When user clicks on {string} then webdriverAgent opens {url}$
public boolean checkifbuttonisclicked(String xpath, String url) throws exception {
// if (driver.findElement(By.xpath(xpath)).Click()) {
//}
if (driver.findElement(By.xpath(xpath)).isSelected()) {
TakeaScreenshotofDesktop(app, yr); //separate function responsible for the screenshot
}
}
So basically,
Scenario Outline:
Load HTML Page (with multiple buttons)
When user clicks on <button>
Open <url> corresponding to the app in the example below
Examples
button | url
App1 | https://stackoverflow.com |
App1 | https://reddit.com |
App1 | https://timer.com |
App2 | https://google.com |
App2 | https://fenty.com |
Share
Improve this question
edited yesterday
guud.purson
asked Dec 27, 2024 at 22:40
guud.pursonguud.purson
113 bronze badges
1 Answer
Reset to default 0It seems like you're making this more complicated than it needs to be.
On the HTML front end page, create an INPUT for each desired application/URL, e.g.
<form action="https://stackoverflow.com">
<input type="submit" value="App1" />
</form>
<form action="https://google.com">
<input type="submit" value="App2" />
</form>
That way when you click on the button, it navigates to the desired URL.
Now for the Java method. You pass in the App name, e.g. "App1", and click on the corresponding INPUT with that value.
public void clickApp(String appName) {
driver.findElement(By.cssSelector("input[value='" + appName + "']")).click();
}
When you do it this way, you don't have to pass in the URL because it's in the HTML of the page. You also don't need to check for .isSelected()
, etc., just click on the corresponding button.
本文标签:
版权声明:本文标题:selenium webdriver - How to write the Java function for Cucumber BDD scenario for "when a user clicks on button&quo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286767a1927737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论