Explorar o código

automated register test

amenpunk hai 1 ano
pai
achega
30653e1529

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

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

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

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

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

@@ -4,9 +4,9 @@ import { useState } from 'react';
4 4
 import { useFormik, Form, FormikProvider } from 'formik';
5 5
 import { Icon } from '@iconify/react';
6 6
 
7
-import {  
8
-    Box, Button,
9
-    Stack, TextField, IconButton, InputAdornment, 
7
+import {
8
+  Box, Button,
9
+  Stack, TextField, IconButton, InputAdornment,
10 10
 } from '@mui/material';
11 11
 
12 12
 import eyeFill from '@iconify/icons-eva/eye-fill';
@@ -15,134 +15,135 @@ import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
15 15
 
16 16
 export function RegisterForm(props) {
17 17
 
18
-    const steplen = 2;
19
-    const index = 0;
20
-
21
-    const [showPassword, setShowPassword] = useState(false);
22
-    const [showPasswordTwo, setShowPasswordTwo] = useState(false);
23
-
24
-    const RegisterSchema = Yup.object().shape({
25
-        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
26
-        lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
27
-        email: Yup.string().email('El correo no es valido').required('Email es requerido'),
28
-        password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
29
-        password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
30
-    });
31
-
32
-    let {client, setClient, handleNext, handleBack } = props
33
-
34
-    const formik = useFormik({
35
-        initialValues: {
36
-            firstName: client.firstName,
37
-            lastName: client.lastName,
38
-            email: client.email,
39
-            password: client.password,
40
-            password_confirm: client.password_confirm
41
-        },
42
-        onSubmit: (fields) => {
43
-            setClient({ 
44
-                ...client,
45
-                ...fields 
46
-            })
47
-            handleNext()
48
-        },
49
-        validationSchema: RegisterSchema,
50
-    });
51
-
52
-    const {errors, touched, handleSubmit, getFieldProps } = formik;
53
-
54
-    return (
55
-        <FormikProvider style={{ padding : 15 }} value={formik}>
56
-            <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
57
-                <Stack spacing={3}>
58
-                    <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
59
-                        <TextField
60
-                            label="Nombre"
61
-                            fullWidth
62
-                            {...getFieldProps('firstName')}
63
-                            error={Boolean(touched.firstName && errors.firstName)}
64
-                            helperText={touched.firstName && errors.firstName}
65
-                        />
66
-
67
-                        <TextField
68
-                            label="Apellidos"
69
-                            fullWidth
70
-                            {...getFieldProps('lastName')}
71
-                            error={Boolean(touched.lastName && errors.lastName)}
72
-                            helperText={touched.lastName && errors.lastName}
73
-                        />
74
-                    </Stack>
75
-
76
-                    <TextField
77
-                        fullWidth
78
-                        autoComplete="username"
79
-                        type="email"
80
-                        label="Correo Electrónico"
81
-                        {...getFieldProps('email')}
82
-                        error={Boolean(touched.email && errors.email)}
83
-                        helperText={touched.email && errors.email}
84
-                    />
85
-
86
-                    <TextField
87
-                        fullWidth
88
-                        autoComplete="current-password"
89
-                        type={showPassword ? 'text' : 'password'}
90
-                        label="Contraseña"
91
-                        {...getFieldProps('password')}
92
-                        InputProps={{
93
-                            endAdornment: (
94
-                                <InputAdornment position="end">
95
-                                    <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
96
-                                        <Icon icon={showPassword ? eyeFill : eyeOffFill} />
97
-                                    </IconButton>
98
-                                </InputAdornment>
99
-                            )
100
-                        }}
101
-                        error={Boolean(touched.password && errors.password)}
102
-                        helperText={touched.password && errors.password}
103
-                    />
104
-
105
-                    <TextField
106
-                        fullWidth
107
-                        type={showPasswordTwo ? 'text' : 'password'}
108
-                        label="Confirma contraseña"
109
-                        {...getFieldProps('password_confirm')}
110
-                        InputProps={{
111
-                            endAdornment: (
112
-                                <InputAdornment position="end">
113
-                                    <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
114
-                                        <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
115
-                                    </IconButton>
116
-                                </InputAdornment>
117
-                            )
118
-                        }}
119
-                        error={Boolean(touched.password_confirm && errors.password_confirm)}
120
-                        helperText={touched.password_confirm && errors.password_confirm}
121
-                    />
122
-
123
-
124
-                  <Box sx={{ mb: 2 }}>
125
-                    <div style={{ paddingTop  : 15}}>
126
-                      <Button
127
-                        type="submit"
128
-                        className="registerBtn" 
129
-                        variant="contained"
130
-                        sx={{ mt: 1, mr: 1 }}
131
-                      >
132
-                        {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
133
-                      </Button>
134
-                      <Button
135
-                        disabled={true}
136
-                        onClick={handleBack}
137
-                        sx={{ mt: 1, mr: 1 }}
138
-                      >
139
-                        Regresar
140
-                      </Button>
141
-                    </div>
142
-                  </Box>
143
-
144
-                </Stack>
145
-            </Form>
146
-        </FormikProvider>
147
-    );
18
+  const steplen = 2;
19
+  const index = 0;
20
+
21
+  const [showPassword, setShowPassword] = useState(false);
22
+  const [showPasswordTwo, setShowPasswordTwo] = useState(false);
23
+
24
+  const RegisterSchema = Yup.object().shape({
25
+    firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
26
+    lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
27
+    email: Yup.string().email('El correo no es valido').required('Email es requerido'),
28
+    password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
29
+    password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
30
+  });
31
+
32
+  let { client, setClient, handleNext, handleBack } = props
33
+
34
+  const formik = useFormik({
35
+    initialValues: {
36
+      firstName: client.firstName,
37
+      lastName: client.lastName,
38
+      email: client.email,
39
+      password: client.password,
40
+      password_confirm: client.password_confirm
41
+    },
42
+    onSubmit: (fields) => {
43
+      setClient({
44
+        ...client,
45
+        ...fields
46
+      })
47
+      handleNext()
48
+    },
49
+    validationSchema: RegisterSchema,
50
+  });
51
+
52
+  const { errors, touched, handleSubmit, getFieldProps } = formik;
53
+
54
+  return (
55
+    <FormikProvider style={{ padding: 15 }} value={formik}>
56
+      <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
57
+        <Stack spacing={3}>
58
+          <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
59
+            <TextField
60
+              label="Nombre"
61
+              fullWidth
62
+              {...getFieldProps('firstName')}
63
+              error={Boolean(touched.firstName && errors.firstName)}
64
+              helperText={touched.firstName && errors.firstName}
65
+            />
66
+
67
+            <TextField
68
+              label="Apellidos"
69
+              fullWidth
70
+              {...getFieldProps('lastName')}
71
+              error={Boolean(touched.lastName && errors.lastName)}
72
+              helperText={touched.lastName && errors.lastName}
73
+            />
74
+          </Stack>
75
+
76
+          <TextField
77
+            fullWidth
78
+            autoComplete="username"
79
+            type="email"
80
+            label="Correo Electrónico"
81
+            {...getFieldProps('email')}
82
+            error={Boolean(touched.email && errors.email)}
83
+            helperText={touched.email && errors.email}
84
+          />
85
+
86
+          <TextField
87
+            fullWidth
88
+            autoComplete="current-password"
89
+            type={showPassword ? 'text' : 'password'}
90
+            label="Contraseña"
91
+            {...getFieldProps('password')}
92
+            InputProps={{
93
+              endAdornment: (
94
+                <InputAdornment position="end">
95
+                  <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
96
+                    <Icon icon={showPassword ? eyeFill : eyeOffFill} />
97
+                  </IconButton>
98
+                </InputAdornment>
99
+              )
100
+            }}
101
+            error={Boolean(touched.password && errors.password)}
102
+            helperText={touched.password && errors.password}
103
+          />
104
+
105
+          <TextField
106
+            fullWidth
107
+            type={showPasswordTwo ? 'text' : 'password'}
108
+            label="Confirma contraseña"
109
+            {...getFieldProps('password_confirm')}
110
+            InputProps={{
111
+              endAdornment: (
112
+                <InputAdornment position="end">
113
+                  <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
114
+                    <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
115
+                  </IconButton>
116
+                </InputAdornment>
117
+              )
118
+            }}
119
+            error={Boolean(touched.password_confirm && errors.password_confirm)}
120
+            helperText={touched.password_confirm && errors.password_confirm}
121
+          />
122
+
123
+
124
+          <Box sx={{ mb: 2 }}>
125
+            <div style={{ paddingTop: 15 }}>
126
+              <Button
127
+                name="submit_first_step"
128
+                type="submit"
129
+                className="registerBtn"
130
+                variant="contained"
131
+                sx={{ mt: 1, mr: 1 }}
132
+              >
133
+                {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
134
+              </Button>
135
+              <Button
136
+                disabled={true}
137
+                onClick={handleBack}
138
+                sx={{ mt: 1, mr: 1 }}
139
+              >
140
+                Regresar
141
+              </Button>
142
+            </div>
143
+          </Box>
144
+
145
+        </Stack>
146
+      </Form>
147
+    </FormikProvider>
148
+  );
148 149
 }

+ 3 - 0
test/.gitignore

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

+ 34 - 0
test/.project

@@ -0,0 +1,34 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>test</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.m2e.core.maven2Builder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+	</buildSpec>
19
+	<natures>
20
+		<nature>org.eclipse.jdt.core.javanature</nature>
21
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
22
+	</natures>
23
+	<filteredResources>
24
+		<filter>
25
+			<id>1697254604875</id>
26
+			<name></name>
27
+			<type>30</type>
28
+			<matcher>
29
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
30
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31
+			</matcher>
32
+		</filter>
33
+	</filteredResources>
34
+</projectDescription>

+ 94 - 0
test/pom.xml

@@ -0,0 +1,94 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<project xmlns="http://maven.apache.org/POM/4.0.0"
4
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6
+  <modelVersion>4.0.0</modelVersion>
7
+
8
+  <groupId>com.psicoweb.test</groupId>
9
+  <artifactId>test</artifactId>
10
+  <version>1.0-SNAPSHOT</version>
11
+
12
+  <name>test</name>
13
+  <!-- FIXME change it to the project's website -->
14
+  <url>http://www.example.com</url>
15
+
16
+  <properties>
17
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18
+    <maven.compiler.source>1.7</maven.compiler.source>
19
+    <maven.compiler.target>1.7</maven.compiler.target>
20
+  </properties>
21
+
22
+  <dependencies>
23
+    <dependency>
24
+      <groupId>junit</groupId>
25
+      <artifactId>junit</artifactId>
26
+      <version>4.11</version>
27
+      <scope>test</scope>
28
+    </dependency>
29
+
30
+    <dependency>
31
+      <groupId>org.seleniumhq.selenium</groupId>
32
+      <artifactId>selenium-java</artifactId>
33
+      <version>4.14.0</version>
34
+    </dependency>
35
+
36
+    <dependency>
37
+      <groupId>com.github.javafaker</groupId>
38
+      <artifactId>javafaker</artifactId>
39
+      <version>0.15</version>
40
+    </dependency>
41
+
42
+
43
+  </dependencies>
44
+
45
+  <build>
46
+    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to
47
+      parent pom) -->
48
+      <plugins>
49
+        <!-- clean lifecycle, see
50
+        https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
51
+        <plugin>
52
+          <artifactId>maven-clean-plugin</artifactId>
53
+          <version>3.1.0</version>
54
+        </plugin>
55
+        <!-- default lifecycle, jar packaging: see
56
+        https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
57
+        <plugin>
58
+          <artifactId>maven-resources-plugin</artifactId>
59
+          <version>3.0.2</version>
60
+        </plugin>
61
+        <plugin>
62
+          <artifactId>maven-compiler-plugin</artifactId>
63
+          <version>3.8.0</version>
64
+        </plugin>
65
+        <plugin>
66
+          <artifactId>maven-surefire-plugin</artifactId>
67
+          <version>2.22.1</version>
68
+        </plugin>
69
+        <plugin>
70
+          <artifactId>maven-jar-plugin</artifactId>
71
+          <version>3.0.2</version>
72
+        </plugin>
73
+        <plugin>
74
+          <artifactId>maven-install-plugin</artifactId>
75
+          <version>2.5.2</version>
76
+        </plugin>
77
+        <plugin>
78
+          <artifactId>maven-deploy-plugin</artifactId>
79
+          <version>2.8.2</version>
80
+        </plugin>
81
+        <!-- site lifecycle, see
82
+        https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
83
+        <plugin>
84
+          <artifactId>maven-site-plugin</artifactId>
85
+          <version>3.7.1</version>
86
+        </plugin>
87
+        <plugin>
88
+          <artifactId>maven-project-info-reports-plugin</artifactId>
89
+          <version>3.0.0</version>
90
+        </plugin>
91
+      </plugins>
92
+    </pluginManagement>
93
+  </build>
94
+</project>

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

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

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

@@ -0,0 +1,79 @@
1
+package com.psicoweb.test;
2
+
3
+import static org.junit.Assert.assertTrue;
4
+
5
+import org.junit.Test;
6
+
7
+import org.openqa.selenium.By;
8
+import org.openqa.selenium.WebDriver;
9
+import org.openqa.selenium.WebElement;
10
+import org.openqa.selenium.chrome.ChromeDriver;
11
+import com.github.javafaker.Faker;
12
+
13
+import java.time.Duration;
14
+import java.util.UUID;
15
+
16
+public class AppTest {
17
+
18
+  @Test
19
+  public void resgister() {
20
+
21
+    WebDriver driver = new ChromeDriver();
22
+    Faker faker = new Faker();
23
+
24
+    String url = "http://localhost:3000/register";
25
+    driver.get(url);
26
+
27
+    driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
28
+
29
+    // NOTE: FIRST FORM
30
+    WebElement nombre = driver.findElement(By.name("firstName"));
31
+    WebElement apellido = driver.findElement(By.name("lastName"));
32
+    WebElement email = driver.findElement(By.name("email"));
33
+    WebElement password = driver.findElement(By.name("password"));
34
+    WebElement password_confirm = driver.findElement(By.name("password_confirm"));
35
+
36
+    WebElement first_form_btn = driver.findElement(By.name("submit_first_step"));
37
+
38
+    nombre.sendKeys(faker.name().firstName());
39
+    apellido.sendKeys(faker.name().lastName());
40
+    email.sendKeys(faker.internet().emailAddress());
41
+    String pass = faker.internet().password();
42
+    password.sendKeys(pass);
43
+    password_confirm.sendKeys(pass);
44
+
45
+    first_form_btn.click();
46
+    
47
+    // NOTE: SECOND FORM
48
+
49
+    WebElement nombre_comercial = driver.findElement(By.name("nombrecpmercial"));
50
+    WebElement telefono = driver.findElement(By.name("telefono"));
51
+    WebElement descripcion = driver.findElement(By.name("decription"));
52
+
53
+    nombre_comercial.sendKeys(faker.company().name());
54
+    telefono.sendKeys("42405339");
55
+    descripcion.sendKeys(faker.company().profession());
56
+
57
+    WebElement second_form_btn = driver.findElement(By.name("submit_second_step"));
58
+    second_form_btn.click();
59
+
60
+    WebElement nit = driver.findElement(By.name("nit"));
61
+    WebElement cui = driver.findElement(By.name("cui"));
62
+    WebElement direccion = driver.findElement(By.name("direccion"));
63
+    WebElement nacimiento = driver.findElement(By.name("nacimiento"));
64
+    WebElement telefono_dos = driver.findElement(By.xpath("//*[@id=\"mui-13\"]"));
65
+
66
+    nit.sendKeys("121212");
67
+    cui.sendKeys("7373982749832");
68
+    direccion.sendKeys(faker.address().streetName());
69
+    nacimiento.sendKeys("10/12/1995");
70
+    telefono_dos.sendKeys("42405339");
71
+
72
+    WebElement submit_btn = driver.findElement(By.name("save_new_client"));
73
+    submit_btn.click();
74
+
75
+    // driver.quit();
76
+
77
+
78
+  }
79
+}