public class Login_Applicant_StepDef {
WebDriver driver;
#Given("^the URL$")
public void the_URL() throws Throwable {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\SSMP\\Downloads\\chromedriver_win32\\ChromeDriver.exe");
driver = new ChromeDriver();
driver.get("http://localhost:4200/app-home");
}
#When("^Click on the Applicant Click here button$")
public void click_on_the_Applicant_Click_here_button() {
driver.findElement(By.xpath("//a[contains(text(),'Candidate click here')]")).click();;
//JavascriptExecutor jvs= (JavascriptExecutor)driver;
//jvs.executeScript("argumnets[0].click()",emailBtn);
}
#Then("^user will navigate to login Page$")
public void user_will_navigate_to_login_Page() {
driver.navigate().to("http://localhost:4200/candidate");
}
#Then("^enter valid \"([^\"]*)\"$")
public void enter_valid_email(String email) {
driver.findElement(By.xpath("//input[#id='mat-input-0']")).sendKeys(email);
}
#Then("^click on Submit button$")
public void click_on_Submit_button() {
driver.findElement(By.xpath("//span[#class='mat-button-wrapper']")).click();
//JavascriptExecutor js= (JavascriptExecutor)driver;
//js.executeScript("argumnets[0]..click()",loginBtn);
}
}
I've created two feature files and step definitions and right now 1 feature file, and step definition linked to TestRunner.How to link multiple FF and Stepdefs to the Test runner
also, Programme is not running with examples though I've added
Applicant login
Test Runner
#App_login
Feature: Optevus Applicant Login Feature
Scenario Outline: login with valid Credentials
Given the URL
When Click on the Applicant Click here button
Then user will navigate to login Page
Then enter valid "<email>"
Then click on Submit button
Examples:
| email |
| kallursh#gmail.com |
| kallurishar#gmail.com |
You didn't state which language you use, buty I'm assuming Java. I have answered some questions about this here and here. That should help you with multiple feature files. I'm not sure you can have multiple glue files/step definitions. But you can use your step definitions to invoke methods in other class files.
In #CucumberOptions, provide folder path where feature files resides in feature option and stepdef folder path in glue option.
Related
My task it to make a cucumber login test, the first step looks like this:
`#Given("^I have open the browser$")
public void openBrowser() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\[REDACTED]\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver.set(new ChromeDriver());
}`
This method runs correctly when I use it in:
public void login(){
System.setProperty("webdriver.chrome.driver", "C:\\Users\\[REDACTED]\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
driver.set(new ChromeDriver(chromeOptions));
driver.get().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get().navigate().to("http://localhost:8080/[REDACTED]/login");
LoginPage.nameTextboxSearch(driver.get()).sendKeys("admin");
LoginPage.passwordTextboxSearch(driver.get()).sendKeys("admin");
LoginPage.buttonSearch(driver.get()).click();
But fails if I try it with cucumber steps.
My feature file:
Feature: Login Action
Scenario: Successful Login with Valid Credentials
Given I have open the browser
And I open SportsBetting App's login website
And I type-in valid username and password
And I click on login button
Then I should be redirected to home page
loginTest.java:
#RunWith(Cucumber.class)
#Cucumber.Options(
features = {"src/test/resources/Login_test.feature"},
glue ={"stepDefinitions"})
public class loginTest{ }
I am having issues implementing a way to navigate a URL where the user simply needs to try and change a variable.
I am unable to use the navigate().to() method as it expects a string but want to know if there is a way around this to be able to navigate to a url?
Code below:
steps page - steps.java
#Given("^I navigate to test website$")
public void i_navigate_to_test_website() throws Throwable {
driver.navigate().to(test.setEnvironment("testEnvironment"));
}
class page - test.java
public void setEnvironment(String platform) {
if(platform.equalsIgnoreCase("testEnvironment"))
{
env= Env1;
}
EnvUsed.add(env);
}
public static String Env1 = "http://www.test1.com";
public static String Env2 = "http://www.test2.com";
public static String Env3 = "http://www.test3.com";
Below answer might help you to navigate url with a variable ( parametric ).
steps page - steps.java
#And("^I navigate to test website$")
public void navigateTestEnv(DataTable testEnv) {
List<List<String>> data = testEnv.raw();
classpage.navigateTestEnv(data.get(1).get(1));
}
class page - test.java
public ProductPage navigateTestEnv(String testEnv) {
driver.navigate().to(testEnv);
}
Cucumber Feature page - test.feature
And I navigate to test website
| Fields | Values |
| testEnv | http://www.test1.com |
My framework consists of TestNG + Cucumber +Jenkins , I'm running the job using bat file configuration in jenkins.
My doubt is , I have a class file to launch the browser and I pass string value to if loop saying ,
if string equals "chrome" then launch the Chrome browser and soon.
Is there a way to pass the chrome value from jenkins into class file ?
example :
public class launch(){
public static String browser ="chrome"
public void LaunchBrowser() throws Exception{
if (browser.equalsIgnoreCase("chrome"))
{
launch chrome driver
}
}
Now i would like to pass the static string value from jenkins ,
Help is appreciated.
Thanks in advance.
You can do something like below
public class Launch {
//You would be passing the Browser flavor using -Dbrowser
//If you don't pass any browser name, then the below logic defaults to chrome
private static String browser =System.getProperty("browser", "chrome");
public void LaunchBrowser() throws Exception {
if (browser.equalsIgnoreCase("chrome")) {
//launch chrome driver
}
}
}
I have the following Java code:
public class Login {
String Login_Status = null;
String Login_Message = null;
#Test
#Parameters({"USERNAME","PASSWORD"})
public void Execute(String UserName, String Password) throws IOException {
try {
Config.driver.findElement(By.linkText("Log in")).click();
Config.driver.findElement(By.id("user_login")).sendKeys(UserName);
Config.driver.findElement(By.id("user_pass")).sendKeys(Password);
Config.driver.findElement(By.id("wp-submit")).click();
// perform validation here
boolean expvalue = Config.driver.findElement(By.xpath("//a[#rel='home']")).isDisplayed();
if (expvalue) {
Login_Status = "PASS";
Login_Message="Login Successfull for user:" + UserName + ",password:" + Password + ",\n EXPECTED: rtMedia Demo Site LINK SHOULD BE PRESENT ON THE HOME PAGE OF rtMedia ACTUAL: rtMedia LINK is PRESENT ON THE HOME PAGE OF rtMedia. DETAILS:NA";
}
} catch(Exception generalException) {
Login_Status = "FAIL";
Login_Message = "Login UnSuccessfull for user:" + UserName + ",password:" + Password + ",\n EXPECTED: rtMedia Demo Site LINK SHOULD BE PRESENT ON THE HOME PAGE OF rtMedia ACTUAL: rtMedia LINK is NOT PRESENT ON THE HOME PAGE OF rtMedia. DETAILS:Exception Occurred:"+generalException.getLocalizedMessage();
// File scrFile = ((TakesScreenshot) Config.driver).getScreenshotAs(OutputType.FILE);
// FileUtils.copyFile(scrFile, new File("C:\\Users\\Public\\Pictures\\failure.png"));
} finally {
Assert.assertTrue(Login_Status.equalsIgnoreCase("PASS"), Login_Message);
}
}
}
I wrote the above Java code for login functionality and now I want to create reports for whatever the result will be (pass or fail) and it should be stored in folder? I have no idea about the generating the reports and also I found the reports are automatically generated by TestNG itself but when we run another test it gets overwritten, that will not help for me. Any help?
There are quite a few ways you can achieve this
If you're using XML report then you can implement IReporter and create a listener. You have to override a method called generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) and you can have your own logic to save the output in a different folder everytime you run the test case.
There is an attribute in testNG called fileFragmentationLevel if you set it to 3 I think your report will not be overwritten. It's in XML reporter class
You can create a listener that will extend TestListenerAdapter and override onStart(ITestContext testContext) method to back up your testoutput folder everytime. But I don't prefer this method.
I prefer #1.
When I am trying to open a site through TestNG, a security page is coming and for that I have click a link text "Continue to this website(not recommended)." that i have done through TestNG coding but it is giving java.lang.NullPointerException error.
and this is the code which i am trying......
public class Registration {
WebDriver driver;
WebElement element;
WebElement element2;
WebDriverWait waiter;
#Test(priority = 1)
public void register_With_Cash() throws RowsExceededException, BiffException, WriteException, IOException
{
File file = new File("D:\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver=new InternetExplorerDriver();
driver.get("https://172.25.155.250/loginpage.aspx");
sleep(10000);
waiter.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Continue to this website (not recommended).")));
driver.findElement(By.linkText("Continue to this website (not recommended).")).click();
sleep(50000);
Thanx in advance for any kind of help.
you can use the below javascript to click the Continue to the Website(not recommended) link.
driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");