thảo luận Tất cả về Automation Test

  • Người tạo chủ đề Người tạo chủ đề Th€@lon€#1
  • Ngày bắt đầu Ngày bắt đầu
bác cần hỏi cái gì?

via theNEXTvoz for iPhone
Sr bác , e quên check voz. Mà h có vấn đề mới bác ạ . Em đang verify 2 hình ảnh, tìm điểm khác biệt và khoanh tròn điểm khác biệt đó :((((. Tìm hiểu mấy hôm nay , chua quá bác ạ ! . Mới làm được tìm điểm khác biệt và hightlight lên chứ chưa khoanh tròn được
 
Sr bác , e quên check voz. Mà h có vấn đề mới bác ạ . Em đang verify 2 hình ảnh, tìm điểm khác biệt và khoanh tròn điểm khác biệt đó :((((. Tìm hiểu mấy hôm nay , chua quá bác ạ ! . Mới làm được tìm điểm khác biệt và hightlight lên chứ chưa khoanh tròn được
bạn dùng ngôn ngữ gì ? mình đang xài C# thì dùng Graphics để vẽ viền vào hình Bitmap:

using (Graphics g = Graphics.FromImage(bitmapImage))
{
// Vẽ viền
using (Pen pen = new Pen(Color.Red, 2)) // Độ dày của viền là 2
{
g.DrawRectangle(pen, x, y, width, height);
}
}
 
bạn dùng ngôn ngữ gì ? mình đang xài C# thì dùng Graphics để vẽ viền vào hình Bitmap:
e có dùng jwt cũng vẽ graphic như bác nói , thì chỉ khoanh được 1 điểm khác biệt , nếu có 2 điểm nó sẽ khoanh 1 vùng to chứa cả 2 điểm chứ không phải 2 hình tròn :((
 
e có dùng jwt cũng vẽ graphic như bác nói , thì chỉ khoanh được 1 điểm khác biệt , nếu có 2 điểm nó sẽ khoanh 1 vùng to chứa cả 2 điểm chứ không phải 2 hình tròn :((
mindset là khoanh được 1 điểm thì sẽ khoanh được n điểm chứ nhỉ ? em tách nó ra làm hàm riêng và mỗi lần khoanh điểm nào em gọi lại trên chính bitmapImage em vừa vẽ xong + đối số x,y,width, height mới muốn khoanh thôi.

Or em có thể xài ChatGPT cho các function đơn giản này mà ?


Java:
import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;


public class HighlightImage {

    

    // Function to draw highlights on an image

    public static void drawHighlights(BufferedImage image, Highlight[] highlights) {

        Graphics2D g2d = image.createGraphics();

        for (Highlight highlight : highlights) {

            g2d.setColor(highlight.color);

            g2d.setStroke(new BasicStroke(highlight.thickness));

            g2d.drawRect(highlight.x, highlight.y, highlight.width, highlight.height);

        }

        g2d.dispose();

    }


    public static void main(String[] args) {

        try {

            // Load image

            File input = new File("input_image.jpg");

            BufferedImage image = ImageIO.read(input);

            

            // Define highlights

            Highlight[] highlights = {

                new Highlight(100, 100, 50, 50, Color.GREEN, 2),  // Green rectangle

                new Highlight(200, 200, 80, 60, Color.RED, 3)      // Red rectangle

                // Add more highlights as needed

            };

            

            // Draw highlights on the image

            drawHighlights(image, highlights);

            

            // Save image

            File output = new File("highlighted_image.jpg");

            ImageIO.write(image, "jpg", output);

        } catch (IOException ex) {

            ex.printStackTrace();

        }

    }

    

    // Class to represent a highlight

    static class Highlight {

        int x, y, width, height, thickness;

        Color color;

        

        Highlight(int x, int y, int width, int height, Color color, int thickness) {

            this.x = x;

            this.y = y;

            this.width = width;

            this.height = height;

            this.color = color;

            this.thickness = thickness;

        }

    }

}
 
mindset là khoanh được 1 điểm thì sẽ khoanh được n điểm chứ nhỉ ? em tách nó ra làm hàm riêng và mỗi lần khoanh điểm nào em gọi lại trên chính bitmapImage em vừa vẽ xong + đối số x,y,width, height mới muốn khoanh thôi.

Or em có thể xài ChatGPT cho các function đơn giản này mà ?


Java:
import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;


public class HighlightImage {

   

    // Function to draw highlights on an image

    public static void drawHighlights(BufferedImage image, Highlight[] highlights) {

        Graphics2D g2d = image.createGraphics();

        for (Highlight highlight : highlights) {

            g2d.setColor(highlight.color);

            g2d.setStroke(new BasicStroke(highlight.thickness));

            g2d.drawRect(highlight.x, highlight.y, highlight.width, highlight.height);

        }

        g2d.dispose();

    }


    public static void main(String[] args) {

        try {

            // Load image

            File input = new File("input_image.jpg");

            BufferedImage image = ImageIO.read(input);

           

            // Define highlights

            Highlight[] highlights = {

                new Highlight(100, 100, 50, 50, Color.GREEN, 2),  // Green rectangle

                new Highlight(200, 200, 80, 60, Color.RED, 3)      // Red rectangle

                // Add more highlights as needed

            };

           

            // Draw highlights on the image

            drawHighlights(image, highlights);

           

            // Save image

            File output = new File("highlighted_image.jpg");

            ImageIO.write(image, "jpg", output);

        } catch (IOException ex) {

            ex.printStackTrace();

        }

    }

   

    // Class to represent a highlight

    static class Highlight {

        int x, y, width, height, thickness;

        Color color;

       

        Highlight(int x, int y, int width, int height, Color color, int thickness) {

            this.x = x;

            this.y = y;

            this.width = width;

            this.height = height;

            this.color = color;

            this.thickness = thickness;

        }

    }

}
code này của a , e chạy thử thì hightlight 2 ô trên 1 ảnh, yêu cầu của đề khoanh 2 điểm khác biệt á a. Mà e đang dùng chạy từng pixel để so sánh tìm điểm. Em mới học auto nên có gì em k hiểu ý a thì e xl
 
mindset là khoanh được 1 điểm thì sẽ khoanh được n điểm chứ nhỉ ? em tách nó ra làm hàm riêng và mỗi lần khoanh điểm nào em gọi lại trên chính bitmapImage em vừa vẽ xong + đối số x,y,width, height mới muốn khoanh thôi.

Or em có thể xài ChatGPT cho các function đơn giản này mà ?


Java:
import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;


public class HighlightImage {

   

    // Function to draw highlights on an image

    public static void drawHighlights(BufferedImage image, Highlight[] highlights) {

        Graphics2D g2d = image.createGraphics();

        for (Highlight highlight : highlights) {

            g2d.setColor(highlight.color);

            g2d.setStroke(new BasicStroke(highlight.thickness));

            g2d.drawRect(highlight.x, highlight.y, highlight.width, highlight.height);

        }

        g2d.dispose();

    }


    public static void main(String[] args) {

        try {

            // Load image

            File input = new File("input_image.jpg");

            BufferedImage image = ImageIO.read(input);

           

            // Define highlights

            Highlight[] highlights = {

                new Highlight(100, 100, 50, 50, Color.GREEN, 2),  // Green rectangle

                new Highlight(200, 200, 80, 60, Color.RED, 3)      // Red rectangle

                // Add more highlights as needed

            };

           

            // Draw highlights on the image

            drawHighlights(image, highlights);

           

            // Save image

            File output = new File("highlighted_image.jpg");

            ImageIO.write(image, "jpg", output);

        } catch (IOException ex) {

            ex.printStackTrace();

        }

    }

   

    // Class to represent a highlight

    static class Highlight {

        int x, y, width, height, thickness;

        Color color;

       

        Highlight(int x, int y, int width, int height, Color color, int thickness) {

            this.x = x;

            this.y = y;

            this.width = width;

            this.height = height;

            this.color = color;

            this.thickness = thickness;

        }

    }

}
package utils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Compare {

public static List<Rectangle> getDifferenceBounds(BufferedImage img1, BufferedImage img2) {
int width = img1.getWidth();
int height = img1.getHeight();
List<Rectangle> diffBoundsList = new ArrayList<>();

// Initialize bounds with invalid values
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pixel1 = img1.getRGB(x, y);
int pixel2 = img2.getRGB(x, y);

if (pixel1 != pixel2) {
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
}
}
int diffWidth = maxX - minX + 1;
int diffHeight = maxY - minY + 1;
Rectangle rectangle = new Rectangle(minX, minY, diffWidth, diffHeight);
diffBoundsList.add(rectangle);
return diffBoundsList;
}
public static BufferedImage getDifferenceImage(BufferedImage img1, BufferedImage img2) {
int differentPixelCount = 0;
// convert images to pixel arrays...
final int w1 = img1.getWidth(),
h1 = img1.getHeight(),
w2 = img2.getWidth(),
h2 = img2.getHeight(),
highlight = Color.MAGENTA.getRGB();
if (w1 != w2 || h1 != h2){
System.out.println("Two picture does not match another! No difference!");
System.exit(1);
}
final int[] p1 = img1.getRGB(0, 0, w1, h1, null, 0, w1);
final int[] p2 = img2.getRGB(0, 0, w2, h2, null, 0, w1);
// compare img1 to img2, pixel by pixel. If different, highlight img1's pixel...
for (int i = 0; i < p1.length; i++) {
if (p1 != p2) {
p1 = highlight;
differentPixelCount++;
}
}
if (differentPixelCount == 0) {
System.out.println("Two picture matches another! No difference!");
System.exit(1);
}
// save img1's pixels to a new BufferedImage, and return it...
// (May require TYPE_INT_ARGB)
BufferedImage out = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
List<Rectangle> recs = getDifferenceBounds(img1, img2);
for(Rectangle rec : recs){
out.setRGB(0, 0, w1, h1, p1, 0, w1);
Graphics2D g2d = out.createGraphics();
g2d.setColor(Color.BLUE);
g2d.drawOval(rec.x - 10, rec.y - 10, rec.width + 20, rec.height + 20);
}
return out;
}

public static void main(String[] args) throws IOException {
ImageIO.write(
getDifferenceImage(
ImageIO.read(new File("C:\\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\expectedImage\\image.png")),
ImageIO.read(new File("C:\\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\image.png"))),
"png",
new File("C:\\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\image3.png"));

}
}

a coi thế này hợp lý chưa
 
package utils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Compare {

public static List<Rectangle> getDifferenceBounds(BufferedImage img1, BufferedImage img2) {
int width = img1.getWidth();
int height = img1.getHeight();
List<Rectangle> diffBoundsList = new ArrayList<>();

// Initialize bounds with invalid values
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pixel1 = img1.getRGB(x, y);
int pixel2 = img2.getRGB(x, y);

if (pixel1 != pixel2) {
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
}
}
int diffWidth = maxX - minX + 1;
int diffHeight = maxY - minY + 1;
Rectangle rectangle = new Rectangle(minX, minY, diffWidth, diffHeight);
diffBoundsList.add(rectangle);
return diffBoundsList;
}
public static BufferedImage getDifferenceImage(BufferedImage img1, BufferedImage img2) {
int differentPixelCount = 0;
// convert images to pixel arrays...
final int w1 = img1.getWidth(),
h1 = img1.getHeight(),
w2 = img2.getWidth(),
h2 = img2.getHeight(),
highlight = Color.MAGENTA.getRGB();
if (w1 != w2 || h1 != h2){
System.out.println("Two picture does not match another! No difference!");
System.exit(1);
}
final int[] p1 = img1.getRGB(0, 0, w1, h1, null, 0, w1);
final int[] p2 = img2.getRGB(0, 0, w2, h2, null, 0, w1);
// compare img1 to img2, pixel by pixel. If different, highlight img1's pixel...
for (int i = 0; i < p1.length; i++) {
if (p1 != p2) {
p1 = highlight;
differentPixelCount++;
}
}
if (differentPixelCount == 0) {
System.out.println("Two picture matches another! No difference!");
System.exit(1);
}
// save img1's pixels to a new BufferedImage, and return it...
// (May require TYPE_INT_ARGB)
BufferedImage out = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
List<Rectangle> recs = getDifferenceBounds(img1, img2);

for(Rectangle rec : recs){
out.setRGB(0, 0, w1, h1, p1, 0, w1);
Graphics2D g2d = out.createGraphics();
g2d.setColor(Color.BLUE);
g2d.drawOval(rec.x - 10, rec.y - 10, rec.width + 20, rec.height + 20);
}

return out;
}

public static void main(String[] args) throws IOException {
ImageIO.write(

getDifferenceImage(
ImageIO.read(new File("C:confused:\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\expectedImage\\image.png")),
ImageIO.read(new File("C:confused:\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\image.png"))),

"png",
new File("C:confused:\Users\\LENOVO\\IdeaProjects\\Example\\src\\test\\resources\\image3.png"));

}
}

a coi thế này hợp lý chưa
à bài toán của em là Compare Image phải không ? Thế thì em sử dụng các thư viện như OpenCV để compare.

Em cứ vào chat GPT gõ keyword: code compare image và highlight điểm khác biệt trong Java, nó sẽ có các example cho em dùng
 
Có anh em nào đang làm với cypress không nhỉ.
Mình đang test 1 web app được build bằng Salesforce
Nó đang dùng Shadow DOM, ở cypress mình đã settings includeShadowDom = true ở file config, nhưng nó cũng ko tìm được element mình cần tìm
Bác nào có kinh nghiệm về cypress với Salesforce không nhỉ help mình vụ này với
 
thím dùng lib nào? selenium hay gì, thường thì thím phải chờ nó render xong, và có khi phải giả click hay gì đó làm mồi đã :v
 
mình đang dính 1 case khá đau đầu liên quan tới docker
Lead muốn build 1 file docker có source để khi chạy container thì chạy được luôn cả test case trong đó
Mình mò mẫm build ra đc 1 cái container có java, có maven, sele server, chrome, chromedriver + các packages liên quan trong cái framework đang xài. Mình cũng chỉ dùng những cái image phổ biến trên dockerhub thôi
Vấn đề là lúc chạy test éo start đc chromedriver. Mình đang xài chrome 125 + chromedriver 125 luôn, mò trên stack, chatgpt đủ kiểu vẫn éo xử lí được, không hiểu là mình làm sai chỗ nào :shame:
Mình có log cả version của tất cả những cái mình cần ra docker log thấy vẫn đủ cả không thiếu thằng nào mà dhs không start đc chromedriver, config chromedriver path các thứ đủ cả
Có cao nhân nào từng gặp trường hợp tương tự hoặc vip pro docker thì vào khai sáng cho mình với. Mình mới đụng vào docker từ tuần trước :shame:
// Project xài java 11, maven 3.6.8
 
Anh em cho xin một vài repo về playwright uy tín để tham khảo trên github với, sắp tới có làm lần đầu với con này
 
  • stabilize framework >> cái tôi hay gặp nhất là cái web lâu lâu nó load quá lâu, hoặc ko load nổi rồi failed ( ca này tôi đặt retry thôi chứ chưa ra cách nào khác), còn việc nó thay đổi logic dẫn đến leak condition nào đó làm script failed hoặc do mình handle cover chưa hết các cases thì phải maintaince lại thôi, ko có gì là hoản hảo 100% cả, tỷ lệ flaky của tôi khá lớn đâu đó >=10% mà phần lớn đến từ việc cái product nó ko stable
  • phần waiting: bên tôi đã migrate từ selenium (chạy thời gian ngắn rồi chuyển luôn) > playwright. tôi ko bài trừ cái gì cả nhưng có những cái nó đã support tận răng nhiều thứ rồi thì nên sài để giảm bớt những cái phức tạp không thực sự cần thiết đi, ngay cái việc ngồi bắt element xpath với css selector lòi mắt ra trong khi chỉ cần ping thằng dev add thêm cho cái test-id vào là xong, team work mạnh lên
  • reuse test framework: phần này tôi đang hiểu là khi build framework mình cần module hoá các phần trong framework đi như action, assertion, untils ..., 2 cái action và assertion thì gần như là auto reuse gần hết rồi, còn cái cục ultis thì hên xui tuỳ vào bài toán mình cần giải. mà những cái này là basic rồi có gì đâu mà thành problem dc hay do tôi vẫn gà quá :D

via theNEXTvoz for iPhone
Thấy mâý bác toàn bàn về UI test k nhỉ, auto còn performance, API test, Data base test nữa mà, UI test là dễ nhất rồi không biết gì lên mạng gõ là có
 

Thống kê chủ đề

Ngày tạo
Th€@lon€#1,
Người trả lời cuối
jokerhehe,
Trả lời
175
Lượt xem
37.033
Quay lại
Lên đầu trang