// Path: src/main/java/com/seleniumtests/core/CustomAssertion.java
// public static void assertThat(final String reason, final boolean assertion) {
//     if (SeleniumTestsContextManager.getThreadContext().isSoftAssertEnabled()) {
//         softAssertThat(reason, assertion);
//     } else {
//         MatcherAssert.assertThat(reason, assertion);
//     }
// }
// 
// Path: src/test/java/com/seleniumtests/webpage/LoginPage.java
// public class LoginPage extends PageObject {
// 
//     private static final TextFieldElement userNameTextBox = new TextFieldElement("Username Textbox",
//             locateByName("usernameLoginPage"));
// 
//     private static final TextFieldElement passwordTextBox = new TextFieldElement("Password Textbox",
//             locateByName("psw1"));
// 
//     private ButtonElement submitButton = new ButtonElement("submit Button",
//             locateByCSSSelector("input~input[value='Submit']"));
// 
//     public LoginPage() throws Exception {
//         super(userNameTextBox);
//     }
// 
//     public LoginPage enterUserName(final String userName) {
//         userNameTextBox.clearAndType(userName);
// 
//         return this;
//     }
// 
//     public LoginPage enterPassword(final String password) {
//         userNameTextBox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public static boolean isUserNameDisplayed() {
//         return userNameTextBox.isDisplayed();
//     }
// 
//     /**
//      * Google Home Page is not part of seleniumtests.com but this how you can move from one page object to another.
//      *
//      * @return
//      *
//      * @throws  Exception
//      */
//     public GoogleHomePage clickSubmitButton() throws Exception {
//         submitButton.click();
// 
//         return new GoogleHomePage();
//     }
// 
//     public GoogleHomePage enterLoginData(final User user) throws Exception {
//         return enterUserName(user.getUserName()).enterPassword(user.getPassword()).clickSubmitButton();
//     }
// }
// 
// Path: src/test/java/com/seleniumtests/webpage/RegistrationPage.java
// public class RegistrationPage extends PageObject {
// 
// 
//     // https://github.com/appium/appium/issues/13306 > w3c standard only declares css and xpath locators
//     private static final TextFieldElement firstNameTextbox = new TextFieldElement("First name text box",
//             locateByCSSSelector("input[name='firstname']"));
// 
//     private TextFieldElement lastNameTextbox = new TextFieldElement("Last name text box", locateByName("lastname"));
// 
//     private TextFieldElement userNameTextbox = new TextFieldElement("user name text box", locateByName("username"));
// 
//     private TextFieldElement pwd1NameTextbox = new TextFieldElement("password 1 text box", locateByName("psw1"));
// 
//     private TextFieldElement pwd2NameTextbox = new TextFieldElement("password 2 text box", locateByName("psw2"));
// 
//     private ButtonElement submitButton = new ButtonElement("submit Button",
//             locateByCSSSelector("input~input[value='Submit']"));
// 
//     public RegistrationPage(final boolean openPageURL) throws Exception {
//         super(firstNameTextbox, openPageURL ? SeleniumTestsContextManager.getThreadContext().getAppURL() : null);
//     }
// 
//     public RegistrationPage enterFirstName(final String firstName) {
//         firstNameTextbox.clearAndType(firstName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterLastName(final String lastName) {
//         lastNameTextbox.clearAndType(lastName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterUserName(final String userName) {
//         userNameTextbox.clearAndType(userName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterPassword(final String password) {
//         pwd1NameTextbox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterConfirmPassword(final String password) {
//         pwd2NameTextbox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public LoginPage clickSubmitButton() throws Exception {
//         submitButton.click();
// 
//         return new LoginPage();
//     }
// 
//     public LoginPage submitValidRegistrationData(final User user) throws Exception {
//         return enterFirstName(user.getFirstName()).enterLastName(user.getLastName()).enterUserName(user.getUserName())
//                                                   .enterPassword(user.getPassword())
//                                                   .enterConfirmPassword(user.getPassword()).clickSubmitButton();
//     }
// 
// }


import com.seleniumtests.webpage.RegistrationPage;
import static com.seleniumtests.core.CustomAssertion.assertThat;
import static org.hamcrest.CoreMatchers.is;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedHashMap;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.seleniumtests.core.Filter;
import com.seleniumtests.core.SeleniumTestPlan;
import com.seleniumtests.dataobject.User;
import com.seleniumtests.util.SpreadSheetHelper;
import com.seleniumtests.util.internal.entity.TestEntity;
import com.seleniumtests.webpage.GoogleHomePage;
import com.seleniumtests.webpage.LoginPage;
/*
 * Copyright 2021 www.seleniumtests.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.seleniumtests.tests;






public class RegistrationTest extends SeleniumTestPlan {

    @DataProvider(
        name = "loginData",
        parallel = true
    )
    public static Iterator<Object[]> getUserInfo(final Method m)
        throws Exception {
        Filter filter = Filter.equalsIgnoreCase(TestEntity.TEST_METHOD,
                m.getName());

        LinkedHashMap<String, Class<?>> classMap =
            new LinkedHashMap<String, Class<?>>();
        classMap.put("TestEntity", TestEntity.class);
        classMap.put("User", User.class);

        return SpreadSheetHelper.getEntitiesFromSpreadsheet(
                RegistrationTest.class, classMap, "loginuser.csv", filter);
    }

    @Test(
        groups = { "registerWithValidUserData" },
        dataProvider = "loginData",
        description = "Register with valid login data"
    )
    public void registerWithValidUserData(final TestEntity testEntity,
        final User user) throws Exception {

// Path: src/main/java/com/seleniumtests/core/CustomAssertion.java
// public static void assertThat(final String reason, final boolean assertion) {
//     if (SeleniumTestsContextManager.getThreadContext().isSoftAssertEnabled()) {
//         softAssertThat(reason, assertion);
//     } else {
//         MatcherAssert.assertThat(reason, assertion);
//     }
// }
// 
// Path: src/test/java/com/seleniumtests/webpage/LoginPage.java
// public class LoginPage extends PageObject {
// 
//     private static final TextFieldElement userNameTextBox = new TextFieldElement("Username Textbox",
//             locateByName("usernameLoginPage"));
// 
//     private static final TextFieldElement passwordTextBox = new TextFieldElement("Password Textbox",
//             locateByName("psw1"));
// 
//     private ButtonElement submitButton = new ButtonElement("submit Button",
//             locateByCSSSelector("input~input[value='Submit']"));
// 
//     public LoginPage() throws Exception {
//         super(userNameTextBox);
//     }
// 
//     public LoginPage enterUserName(final String userName) {
//         userNameTextBox.clearAndType(userName);
// 
//         return this;
//     }
// 
//     public LoginPage enterPassword(final String password) {
//         userNameTextBox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public static boolean isUserNameDisplayed() {
//         return userNameTextBox.isDisplayed();
//     }
// 
//     /**
//      * Google Home Page is not part of seleniumtests.com but this how you can move from one page object to another.
//      *
//      * @return
//      *
//      * @throws  Exception
//      */
//     public GoogleHomePage clickSubmitButton() throws Exception {
//         submitButton.click();
// 
//         return new GoogleHomePage();
//     }
// 
//     public GoogleHomePage enterLoginData(final User user) throws Exception {
//         return enterUserName(user.getUserName()).enterPassword(user.getPassword()).clickSubmitButton();
//     }
// }
// 
// Path: src/test/java/com/seleniumtests/webpage/RegistrationPage.java
// public class RegistrationPage extends PageObject {
// 
// 
//     // https://github.com/appium/appium/issues/13306 > w3c standard only declares css and xpath locators
//     private static final TextFieldElement firstNameTextbox = new TextFieldElement("First name text box",
//             locateByCSSSelector("input[name='firstname']"));
// 
//     private TextFieldElement lastNameTextbox = new TextFieldElement("Last name text box", locateByName("lastname"));
// 
//     private TextFieldElement userNameTextbox = new TextFieldElement("user name text box", locateByName("username"));
// 
//     private TextFieldElement pwd1NameTextbox = new TextFieldElement("password 1 text box", locateByName("psw1"));
// 
//     private TextFieldElement pwd2NameTextbox = new TextFieldElement("password 2 text box", locateByName("psw2"));
// 
//     private ButtonElement submitButton = new ButtonElement("submit Button",
//             locateByCSSSelector("input~input[value='Submit']"));
// 
//     public RegistrationPage(final boolean openPageURL) throws Exception {
//         super(firstNameTextbox, openPageURL ? SeleniumTestsContextManager.getThreadContext().getAppURL() : null);
//     }
// 
//     public RegistrationPage enterFirstName(final String firstName) {
//         firstNameTextbox.clearAndType(firstName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterLastName(final String lastName) {
//         lastNameTextbox.clearAndType(lastName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterUserName(final String userName) {
//         userNameTextbox.clearAndType(userName);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterPassword(final String password) {
//         pwd1NameTextbox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public RegistrationPage enterConfirmPassword(final String password) {
//         pwd2NameTextbox.clearAndType(password);
// 
//         return this;
//     }
// 
//     public LoginPage clickSubmitButton() throws Exception {
//         submitButton.click();
// 
//         return new LoginPage();
//     }
// 
//     public LoginPage submitValidRegistrationData(final User user) throws Exception {
//         return enterFirstName(user.getFirstName()).enterLastName(user.getLastName()).enterUserName(user.getUserName())
//                                                   .enterPassword(user.getPassword())
//                                                   .enterConfirmPassword(user.getPassword()).clickSubmitButton();
//     }
// 
// }


// Path: src/test/java/com/seleniumtests/tests/RegistrationTest.java
import com.seleniumtests.webpage.RegistrationPage;
import static com.seleniumtests.core.CustomAssertion.assertThat;
import static org.hamcrest.CoreMatchers.is;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedHashMap;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.seleniumtests.core.Filter;
import com.seleniumtests.core.SeleniumTestPlan;
import com.seleniumtests.dataobject.User;
import com.seleniumtests.util.SpreadSheetHelper;
import com.seleniumtests.util.internal.entity.TestEntity;
import com.seleniumtests.webpage.GoogleHomePage;
import com.seleniumtests.webpage.LoginPage;

/*
 * Copyright 2021 www.seleniumtests.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.seleniumtests.tests;






public class RegistrationTest extends SeleniumTestPlan {

    @DataProvider(
        name = "loginData",
        parallel = true
    )
    public static Iterator<Object[]> getUserInfo(final Method m)
        throws Exception {
        Filter filter = Filter.equalsIgnoreCase(TestEntity.TEST_METHOD,
                m.getName());

        LinkedHashMap<String, Class<?>> classMap =
            new LinkedHashMap<String, Class<?>>();
        classMap.put("TestEntity", TestEntity.class);
        classMap.put("User", User.class);

        return SpreadSheetHelper.getEntitiesFromSpreadsheet(
                RegistrationTest.class, classMap, "loginuser.csv", filter);
    }

    @Test(
        groups = { "registerWithValidUserData" },
        dataProvider = "loginData",
        description = "Register with valid login data"
    )
    public void registerWithValidUserData(final TestEntity testEntity,
        final User user) throws Exception {

        new RegistrationPage(true).submitValidRegistrationData(user);