浏览代码

automated register test

amenpunk 2 年之前
父节点
当前提交
30653e1529

+ 1 - 0
src/Components/Register/Company.jsx

@@ -71,6 +71,7 @@ export function Company(props) {
           <Box sx={{ mb: 2 }}>
             <div style={{ paddingTop: 15 }}>
               <Button
+                name="submit_second_step"
                 type="submit"
                 className="registerBtn"
                 variant="contained"

+ 1 - 0
src/Components/Register/PersonalInfo.js

@@ -141,6 +141,7 @@ export function PersonalInfo(props) {
           <Box sx={{ mb: 2 }}>
             <div style={{ paddingTop: 15 }}>
               <Button
+                name="save_new_client"
                 type="submit"
                 className="registerBtn"
                 variant="contained"

+ 134 - 133
src/Components/Register/RegisterForm.jsx

@@ -4,9 +4,9 @@ import { useState } from 'react';
 import { useFormik, Form, FormikProvider } from 'formik';
 import { Icon } from '@iconify/react';
 
-import {  
-    Box, Button,
-    Stack, TextField, IconButton, InputAdornment, 
+import {
+  Box, Button,
+  Stack, TextField, IconButton, InputAdornment,
 } from '@mui/material';
 
 import eyeFill from '@iconify/icons-eva/eye-fill';
@@ -15,134 +15,135 @@ import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
 
 export function RegisterForm(props) {
 
-    const steplen = 2;
-    const index = 0;
-
-    const [showPassword, setShowPassword] = useState(false);
-    const [showPasswordTwo, setShowPasswordTwo] = useState(false);
-
-    const RegisterSchema = Yup.object().shape({
-        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
-        lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
-        email: Yup.string().email('El correo no es valido').required('Email es requerido'),
-        password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
-        password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
-    });
-
-    let {client, setClient, handleNext, handleBack } = props
-
-    const formik = useFormik({
-        initialValues: {
-            firstName: client.firstName,
-            lastName: client.lastName,
-            email: client.email,
-            password: client.password,
-            password_confirm: client.password_confirm
-        },
-        onSubmit: (fields) => {
-            setClient({ 
-                ...client,
-                ...fields 
-            })
-            handleNext()
-        },
-        validationSchema: RegisterSchema,
-    });
-
-    const {errors, touched, handleSubmit, getFieldProps } = formik;
-
-    return (
-        <FormikProvider style={{ padding : 15 }} value={formik}>
-            <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
-                <Stack spacing={3}>
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
-                        <TextField
-                            label="Nombre"
-                            fullWidth
-                            {...getFieldProps('firstName')}
-                            error={Boolean(touched.firstName && errors.firstName)}
-                            helperText={touched.firstName && errors.firstName}
-                        />
-
-                        <TextField
-                            label="Apellidos"
-                            fullWidth
-                            {...getFieldProps('lastName')}
-                            error={Boolean(touched.lastName && errors.lastName)}
-                            helperText={touched.lastName && errors.lastName}
-                        />
-                    </Stack>
-
-                    <TextField
-                        fullWidth
-                        autoComplete="username"
-                        type="email"
-                        label="Correo Electrónico"
-                        {...getFieldProps('email')}
-                        error={Boolean(touched.email && errors.email)}
-                        helperText={touched.email && errors.email}
-                    />
-
-                    <TextField
-                        fullWidth
-                        autoComplete="current-password"
-                        type={showPassword ? 'text' : 'password'}
-                        label="Contraseña"
-                        {...getFieldProps('password')}
-                        InputProps={{
-                            endAdornment: (
-                                <InputAdornment position="end">
-                                    <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
-                                        <Icon icon={showPassword ? eyeFill : eyeOffFill} />
-                                    </IconButton>
-                                </InputAdornment>
-                            )
-                        }}
-                        error={Boolean(touched.password && errors.password)}
-                        helperText={touched.password && errors.password}
-                    />
-
-                    <TextField
-                        fullWidth
-                        type={showPasswordTwo ? 'text' : 'password'}
-                        label="Confirma contraseña"
-                        {...getFieldProps('password_confirm')}
-                        InputProps={{
-                            endAdornment: (
-                                <InputAdornment position="end">
-                                    <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
-                                        <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
-                                    </IconButton>
-                                </InputAdornment>
-                            )
-                        }}
-                        error={Boolean(touched.password_confirm && errors.password_confirm)}
-                        helperText={touched.password_confirm && errors.password_confirm}
-                    />
-
-
-                  <Box sx={{ mb: 2 }}>
-                    <div style={{ paddingTop  : 15}}>
-                      <Button
-                        type="submit"
-                        className="registerBtn" 
-                        variant="contained"
-                        sx={{ mt: 1, mr: 1 }}
-                      >
-                        {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
-                      </Button>
-                      <Button
-                        disabled={true}
-                        onClick={handleBack}
-                        sx={{ mt: 1, mr: 1 }}
-                      >
-                        Regresar
-                      </Button>
-                    </div>
-                  </Box>
-
-                </Stack>
-            </Form>
-        </FormikProvider>
-    );
+  const steplen = 2;
+  const index = 0;
+
+  const [showPassword, setShowPassword] = useState(false);
+  const [showPasswordTwo, setShowPasswordTwo] = useState(false);
+
+  const RegisterSchema = Yup.object().shape({
+    firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
+    lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
+    email: Yup.string().email('El correo no es valido').required('Email es requerido'),
+    password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
+    password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
+  });
+
+  let { client, setClient, handleNext, handleBack } = props
+
+  const formik = useFormik({
+    initialValues: {
+      firstName: client.firstName,
+      lastName: client.lastName,
+      email: client.email,
+      password: client.password,
+      password_confirm: client.password_confirm
+    },
+    onSubmit: (fields) => {
+      setClient({
+        ...client,
+        ...fields
+      })
+      handleNext()
+    },
+    validationSchema: RegisterSchema,
+  });
+
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
+
+  return (
+    <FormikProvider style={{ padding: 15 }} value={formik}>
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
+        <Stack spacing={3}>
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
+            <TextField
+              label="Nombre"
+              fullWidth
+              {...getFieldProps('firstName')}
+              error={Boolean(touched.firstName && errors.firstName)}
+              helperText={touched.firstName && errors.firstName}
+            />
+
+            <TextField
+              label="Apellidos"
+              fullWidth
+              {...getFieldProps('lastName')}
+              error={Boolean(touched.lastName && errors.lastName)}
+              helperText={touched.lastName && errors.lastName}
+            />
+          </Stack>
+
+          <TextField
+            fullWidth
+            autoComplete="username"
+            type="email"
+            label="Correo Electrónico"
+            {...getFieldProps('email')}
+            error={Boolean(touched.email && errors.email)}
+            helperText={touched.email && errors.email}
+          />
+
+          <TextField
+            fullWidth
+            autoComplete="current-password"
+            type={showPassword ? 'text' : 'password'}
+            label="Contraseña"
+            {...getFieldProps('password')}
+            InputProps={{
+              endAdornment: (
+                <InputAdornment position="end">
+                  <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
+                    <Icon icon={showPassword ? eyeFill : eyeOffFill} />
+                  </IconButton>
+                </InputAdornment>
+              )
+            }}
+            error={Boolean(touched.password && errors.password)}
+            helperText={touched.password && errors.password}
+          />
+
+          <TextField
+            fullWidth
+            type={showPasswordTwo ? 'text' : 'password'}
+            label="Confirma contraseña"
+            {...getFieldProps('password_confirm')}
+            InputProps={{
+              endAdornment: (
+                <InputAdornment position="end">
+                  <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
+                    <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
+                  </IconButton>
+                </InputAdornment>
+              )
+            }}
+            error={Boolean(touched.password_confirm && errors.password_confirm)}
+            helperText={touched.password_confirm && errors.password_confirm}
+          />
+
+
+          <Box sx={{ mb: 2 }}>
+            <div style={{ paddingTop: 15 }}>
+              <Button
+                name="submit_first_step"
+                type="submit"
+                className="registerBtn"
+                variant="contained"
+                sx={{ mt: 1, mr: 1 }}
+              >
+                {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
+              </Button>
+              <Button
+                disabled={true}
+                onClick={handleBack}
+                sx={{ mt: 1, mr: 1 }}
+              >
+                Regresar
+              </Button>
+            </div>
+          </Box>
+
+        </Stack>
+      </Form>
+    </FormikProvider>
+  );
 }

+ 3 - 0
test/.gitignore

@@ -0,0 +1,3 @@
+target
+.settings
+.classpath

+ 34 - 0
test/.project

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+	<filteredResources>
+		<filter>
+			<id>1697254604875</id>
+			<name></name>
+			<type>30</type>
+			<matcher>
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
+</projectDescription>

+ 94 - 0
test/pom.xml

@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>com.psicoweb.test</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>test</name>
+  <!-- FIXME change it to the project's website -->
+  <url>http://www.example.com</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.seleniumhq.selenium</groupId>
+      <artifactId>selenium-java</artifactId>
+      <version>4.14.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.github.javafaker</groupId>
+      <artifactId>javafaker</artifactId>
+      <version>0.15</version>
+    </dependency>
+
+
+  </dependencies>
+
+  <build>
+    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to
+      parent pom) -->
+      <plugins>
+        <!-- clean lifecycle, see
+        https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+        <plugin>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <!-- default lifecycle, jar packaging: see
+        https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.22.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>2.5.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>2.8.2</version>
+        </plugin>
+        <!-- site lifecycle, see
+        https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>3.7.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-project-info-reports-plugin</artifactId>
+          <version>3.0.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

+ 8 - 0
test/src/main/java/com/psicoweb/test/App.java

@@ -0,0 +1,8 @@
+package com.psicoweb.test;
+
+
+public class App {
+  public static void main(String[] args) {
+
+  }
+}

+ 79 - 0
test/src/test/java/com/psicoweb/test/AppTest.java

@@ -0,0 +1,79 @@
+package com.psicoweb.test;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.chrome.ChromeDriver;
+import com.github.javafaker.Faker;
+
+import java.time.Duration;
+import java.util.UUID;
+
+public class AppTest {
+
+  @Test
+  public void resgister() {
+
+    WebDriver driver = new ChromeDriver();
+    Faker faker = new Faker();
+
+    String url = "http://localhost:3000/register";
+    driver.get(url);
+
+    driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
+
+    // NOTE: FIRST FORM
+    WebElement nombre = driver.findElement(By.name("firstName"));
+    WebElement apellido = driver.findElement(By.name("lastName"));
+    WebElement email = driver.findElement(By.name("email"));
+    WebElement password = driver.findElement(By.name("password"));
+    WebElement password_confirm = driver.findElement(By.name("password_confirm"));
+
+    WebElement first_form_btn = driver.findElement(By.name("submit_first_step"));
+
+    nombre.sendKeys(faker.name().firstName());
+    apellido.sendKeys(faker.name().lastName());
+    email.sendKeys(faker.internet().emailAddress());
+    String pass = faker.internet().password();
+    password.sendKeys(pass);
+    password_confirm.sendKeys(pass);
+
+    first_form_btn.click();
+    
+    // NOTE: SECOND FORM
+
+    WebElement nombre_comercial = driver.findElement(By.name("nombrecpmercial"));
+    WebElement telefono = driver.findElement(By.name("telefono"));
+    WebElement descripcion = driver.findElement(By.name("decription"));
+
+    nombre_comercial.sendKeys(faker.company().name());
+    telefono.sendKeys("42405339");
+    descripcion.sendKeys(faker.company().profession());
+
+    WebElement second_form_btn = driver.findElement(By.name("submit_second_step"));
+    second_form_btn.click();
+
+    WebElement nit = driver.findElement(By.name("nit"));
+    WebElement cui = driver.findElement(By.name("cui"));
+    WebElement direccion = driver.findElement(By.name("direccion"));
+    WebElement nacimiento = driver.findElement(By.name("nacimiento"));
+    WebElement telefono_dos = driver.findElement(By.xpath("//*[@id=\"mui-13\"]"));
+
+    nit.sendKeys("121212");
+    cui.sendKeys("7373982749832");
+    direccion.sendKeys(faker.address().streetName());
+    nacimiento.sendKeys("10/12/1995");
+    telefono_dos.sendKeys("42405339");
+
+    WebElement submit_btn = driver.findElement(By.name("save_new_client"));
+    submit_btn.click();
+
+    // driver.quit();
+
+
+  }
+}